Next.js 13中间件报错[TypeError: Class extends value undefined...]求助
Next.js 13 中间件报错 TypeError: Class extends value undefined is not a constructor or null 解决方案
这个错误源于Next.js 13与旧版本的undici(Next.js内置HTTP客户端)不兼容,你的环境中使用的undici@5.11.0在Edge Runtime环境下存在类继承的兼容性问题。以下是具体解决步骤:
升级undici到兼容版本
在项目根目录执行命令,安装与Next.js 13兼容的undici版本:pnpm add undici@^5.20.0清理依赖缓存与构建缓存
- 删除旧依赖文件:
rm -rf node_modules pnpm-lock.yaml - 重新安装依赖:
pnpm install - 清理Next.js构建缓存:
pnpm dlx next clean
- 删除旧依赖文件:
升级Next.js到最新稳定版
如果上述步骤无效,尝试升级Next.js及相关依赖到13.x系列的最新稳定版本:pnpm add next@latest react@latest react-dom@latest
你的中间件代码逻辑符合Next.js 13规范,无需修改,解决依赖兼容问题后即可正常运行。
内容的提问来源于stack exchange,提问作者y-tom
相关产品推荐
相关产品推荐

