You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Tortoise SVN下载的React.js项目yarn start报错求助

问题解决:Next.js执行yarn start报错找不到生产构建文件

问题描述

从SVN拉取公司React.js(Next.js)项目后,执行yarn start时报错,提示无法找到C:\Projects\Old EHR\.next目录下的生产构建文件,要求先执行next build;但执行yarn dev可以正常启动开发服务。已尝试重新安装依赖,问题仍未解决。

命令行报错输出:

PS C:\Projects\Old EHR> yarn start
yarn run v1.22.19
$ next start
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
Error: Could not find a production build in the 'C:\Projects\Old EHR\.next' directory. Try building your app 
with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
    at NextNodeServer.getBuildId (C:\Projects\Old EHR\node_modules\next\dist\server\next-server.js:165:23)   
    at new Server (C:\Projects\Old EHR\node_modules\next\dist\server\base-server.js:56:29)
    at new NextNodeServer (C:\Projects\Old EHR\node_modules\next\dist\server\next-server.js:67:9)
    at NextServer.createServer (C:\Projects\Old EHR\node_modules\next\dist\server\next.js:144:16)
    at async C:\Projects\Old EHR\node_modules\next\dist\server\next.js:156:31
    at async NextServer.prepare (C:\Projects\Old EHR\node_modules\next\dist\server\next.js:131:24)
    at async C:\Projects\Old EHR\node_modules\next\dist\cli\next-start.js:116:9
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

yarn dev正常输出:

PS C:\Projects\Old EHR> yarn dev
yarn run v1.22.19
$ next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - compiled client and server successfully in 722 ms (136 modules)

解决步骤

1. 手动执行生产构建命令

直接在项目根目录执行构建命令,重点关注执行过程中是否有报错:

yarn build

如果出现依赖缺失、语法错误或资源路径问题,根据提示修复后重新执行构建。

2. 检查版本兼容性

确认项目Next.js版本与本地Node.js版本匹配:

  • 打开项目package.json,查看next字段的版本号
  • Next.js 13+建议使用Node.js 16.8及以上版本,旧版本对应更低的Node.js要求
    版本不兼容时,升级/降级Node.js后重新安装依赖并构建。

3. 清理缓存后重新构建

执行以下命令清理缓存、重置依赖,再重新构建:

# 清理Next.js缓存
yarn cache clean
rm -rf .next
# 重置依赖
rm -rf node_modules yarn.lock
yarn install
# 重新构建
yarn build

Windows环境下使用PowerShell命令删除文件:

Remove-Item .next -Recurse -Force
Remove-Item node_modules -Recurse -Force
Remove-Item yarn.lock

4. 检查目录权限

确保当前用户对C:\Projects\Old EHR目录拥有读写权限,避免因权限不足导致无法生成.next构建目录。

验证

执行yarn build后,确认项目根目录生成.next文件夹,再执行yarn start即可正常启动生产服务器。

内容的提问来源于stack exchange,提问作者Newbie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 01:25:25