Next.js 13.3.1构建失败:实验性app目录本地正常但生产构建报错
Next.js 实验性App目录生产构建失败(TypeError: Expected a non-empty string)
本地运行正常,但执行生产构建时持续失败,报错信息如下:
info - Creating an optimized production build .info - TypeError: Expected a non-empty string at picomatch.makeRe (/Users/himanshubhardwaz/web/personal/my-app/node_modules/next/dist/compiled/micromatch/index.js:15:21418) at micromatch.makeRe (/Users/himanshubhardwaz/web/personal/my-app/node_modules/next/dist/compiled/micromatch/index.js:15:2615) at /Users/himanshubhardwaz/web/personal/my-app/node_modules/next/dist/build/index.js:1758:54 at Array.map (<anonymous>) at /Users/himanshubhardwaz/web/personal/my-app/node_modules/next/dist/build/index.js:1753:155 at async Span.traceAsyncFn (/Users/himanshubhardwaz/web/personal/my-app/node_modules/next/dist/trace/trace.js:97:20) at async build (/Users/himanshubhardwaz/web/personal/my-app/node_modules/next/dist/build/index.js:143:29)
已尝试清理构建缓存、重新安装node_modules,问题未解决。以下是针对性排查方案:
- 检查
next.config.js配置:重点排查路径相关的配置项,比如transpilePackages、images.remotePatterns、experimental字段下的路径规则,确保没有空字符串、未定义变量或空数组项。例如transpilePackages: ['', 'some-package']这类包含空字符串的配置会触发该错误。 - 验证构建命令参数:查看
package.json中的build脚本,确认没有传入空参数(如next build "")。 - 检查环境变量:确认构建时依赖的环境变量(如涉及资源路径、静态文件目录的变量)没有空值,避免空字符串被传入路径匹配逻辑。
- 排查App目录文件结构:检查是否存在名称为空的文件/文件夹,或文件名包含特殊字符,导致micromatch匹配时出错。
- 升级/降级Next.js版本:该错误可能是特定版本的bug,尝试升级到最新稳定版(执行
npm install next@latest),或降级到之前能正常构建的版本。 - 检查忽略规则文件:查看
.gitignore、.nextignore文件,删除空行或无效的匹配规则(如单独的*或空字符串行)。
内容的提问来源于stack exchange,提问作者himanshu bhardwaz
相关产品推荐
相关产品推荐

