错误:命令“npm run build”以 1 退出。vercel deploy 错误与 next.js
Posted
技术标签:
【中文标题】错误:命令“npm run build”以 1 退出。vercel deploy 错误与 next.js【英文标题】:Error: Command "npm run build" exited with 1. vercel deploy error with next.js 【发布时间】:2021-08-08 16:54:36 【问题描述】:我正在尝试使用 vercel 和我的 git 存储库部署我的 next.js 网站。这是我从 vercel deploy 网站控制台得到的消息。 尝试安装 emoition/react 仍然无法正常工作。
14:59:59.757 Cloning github.com/dor29494/my-app (Branch: test, Commit: 400d8a4)
15:00:00.829 Cloning completed: 1.072s
15:00:00.851 Analyzing source code...
15:00:01.658 Installing build runtime...
15:00:04.373 Build runtime installed: 2.715s
15:00:06.725 Build cache not provided
15:00:07.847 Installing dependencies...
15:00:08.325 npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
15:00:19.992 > core-js@3.6.5 postinstall /vercel/path0/node_modules/core-js
15:00:19.992 > node -e "tryrequire('./postinstall')catch(e)"
15:00:20.088 > protobufjs@6.10.2 postinstall /vercel/path0/node_modules/protobufjs
15:00:20.088 > node scripts/postinstall
15:00:20.443 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
15:00:20.443 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")
15:00:20.445 added 539 packages from 364 contributors in 12.152s
15:00:20.626 31 packages are looking for funding
15:00:20.626 run `npm fund` for details
15:00:20.648 Detected Next.js version: 10.0.8
15:00:20.649 Running "npm run build"
15:00:20.861 > learn-starter@0.1.0 build /vercel/path0
15:00:20.861 > next build
15:00:21.906 info - Creating an optimized production build...
15:00:21.922 Attention: Next.js now collects completely anonymous telemetry regarding usage.
15:00:21.922 This information is used to shape Next.js' roadmap and prioritize features.
15:00:21.922 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
15:00:21.922 https://nextjs.org/telemetry
15:00:26.563 Failed to compile.
15:00:26.563 ModuleNotFoundError: Module not found: Error: Can't resolve '@emotion/styled' in '/vercel/path0/node_modules/@material-ui/core/node_modules/@material-ui/styled-engine'
15:00:26.563 > Build error occurred
15:00:26.564 Error: > Build failed because of webpack errors
15:00:26.564 at /vercel/path0/node_modules/next/dist/build/index.js:15:918
15:00:26.564 at runMicrotasks (<anonymous>)
15:00:26.564 at processTicksAndRejections (internal/process/task_queues.js:93:5)
15:00:26.564 at async /vercel/path0/node_modules/next/dist/build/tracer.js:3:470
15:00:26.578 npm ERR! code ELIFECYCLE
15:00:26.578 npm ERR! errno 1
15:00:26.581 npm ERR! learn-starter@0.1.0 build: `next build`
15:00:26.581 npm ERR! Exit status 1
15:00:26.581 npm ERR!
15:00:26.581 npm ERR! Failed at the learn-starter@0.1.0 build script.
15:00:26.581 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
15:00:26.589 npm ERR! A complete log of this run can be found in:
15:00:26.589 npm ERR! /vercel/.npm/_logs/2021-05-19T12_00_26_582Z-debug.log
15:00:26.601 Error: Command "npm run build" exited with 1
【问题讨论】:
几天前我遇到了同样的问题。这是 Vercel 的错误。只是重建它几次。对我来说,它在 3 次重建后取得了成功。 【参考方案1】:Error: Command “npm run build” exited with 1
不是 Vercel 显示的实际错误。
实际错误以红色显示在日志中。
示例错误日志
在您的日志中,您可以看到导致构建过程失败的Can't resolve '@emotion/styled'
错误。
你必须先修复它。
【讨论】:
以上是关于错误:命令“npm run build”以 1 退出。vercel deploy 错误与 next.js的主要内容,如果未能解决你的问题,请参考以下文章
反应:npm start 工作,npm run build 抛出 ELIFECYCLE 错误(errno 1)
我在 Windows 上收到“npm run build”部署错误 [重复]