next.js 部署到Vercel时出现对等依赖关系错误

wbgh16ku  于 2022-12-03  发布在  其他
关注(0)|答案(1)|浏览(139)

我尝试将我的NextJS应用程序部署到Vercel上,但每次在部署阶段,我都会遇到这些错误,部署将失败:

Previous build cache not available
Cloning completed: 426.52ms
Running "vercel build"
Vercel CLI 28.6.0
Installing dependencies...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: react-typed@1.2.0
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   react@"18.2.0" from the root project
npm ERR!   peer react@"^18.2.0" from next@13.0.5
npm ERR!   node_modules/next
npm ERR!     next@"13.0.5" from the root project
npm ERR!   3 more (react-dom, react-icons, styled-jsx)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.3.0" from react-typed@1.2.0
npm ERR! node_modules/react-typed
npm ERR!   react-typed@"^1.2.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@16.14.0
npm ERR! node_modules/react
npm ERR!   peer react@"^16.3.0" from react-typed@1.2.0
npm ERR!   node_modules/react-typed
npm ERR!     react-typed@"^1.2.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /vercel/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR!     /vercel/.npm/_logs/2022-12-02T16_42_09_037Z-debug-0.log
Error: Command "npm install" exited with 1

我试过运行npm install --legacy-peer-deps并尝试重新部署到Vercel上,但同样的问题仍然存在。当我在localhost:3000上使用npm run dev运行此应用程序时,应用程序呈现良好。有人知道我可以做什么吗?
我试过了

npm install --legacy-peer-deps

并将这些更改推送到我的GitHub仓库中。重新部署时,仍然会出现同样的问题。

npm install --legacy-peer-deps

但这一次,没有更多的变化要做。

zf9nrax1

zf9nrax11#

您可以通过以下方式覆盖Vercel CLI使用的安装命令:
1.转到Vercel Jmeter 板-〉-〉设置-〉常规-〉滚动到构建和开发设置并在安装命令中输入npm install --legacy-peer-deps
1.在项目的根目录中创建vercel.json文件,该文件应包含:

// vercel.json
{
  "installCommand": "npm install --legacy-peer-deps"
}

在推送并等待部署之后,它应该经历这段时间
但我建议查找这个问题的原因,好像你使用的某个依赖项依赖于react-typed,后者已经不维护了,还是寻求替代

相关问题