原因:build 阶段没有构建完成,虽然提示 Compiled successfully,但实际上没有构建完,需要根据后面的提示来排障。
历程
在执行 npm run build 后执行 npm run start,报错:
▲ Next.js 14.1.4
- Local: http://localhost:3000
Error: ENOENT: no such file or directory, open '.next\BUILD_ID'
...经过排查发现,实际上是 build 阶段未完成,但报错不是很明显:
✓ Compiled successfully
✓ Collecting page data
> Build optimization failed: found pages without a React Component as default export in
pages/api-list
See https://nextjs.org/docs/messages/page-without-valid-component for more info.虽然提示 Compiled successfully,但是实际上并没有完成。因为我错误地将 api-list.js 放入了 pages 目录下。
将该文件改到其他目录,成功构建完成。