由于依赖问题,Heroku 未部署构建

Ama*_*l J 5 heroku shopify

在heroku中部署构建时,它导致依赖错误,有人遇到过同样的情况吗?根本原因是什么?有办法解决这个问题吗?heroku 构建以前可以工作,但现在发生了这个错误,这真的很令人困惑

remote: -----> Installing dependencies
    remote:        Installing node modules
    remote:        npm ERR! code ERESOLVE
    remote:        npm ERR! ERESOLVE could not resolve
    remote:        npm ERR! 
    remote:        npm ERR! While resolving: next@12.1.6
    remote:        npm ERR! Found: react@16.14.0
    remote:        npm ERR! node_modules/react
    remote:        npm ERR!   react@"^16.10.1" from the root project
    remote:        npm ERR!   peer react@"^16.8.0" from @apollo/react-common@3.1.4
    remote:        npm ERR!   node_modules/@apollo/react-common
    remote:        npm ERR!     @apollo/react-common@"^3.1.4" from @apollo/react-components@3.1.5
    remote:        npm ERR!     node_modules/@apollo/react-components
    remote:        npm ERR!       @apollo/react-components@"^3.1.5" from @apollo/react-hoc@3.1.5
    remote:        npm ERR!       node_modules/@apollo/react-hoc
    remote:        npm ERR!         @apollo/react-hoc@"^3.1.5" from react-apollo@3.1.5
    remote:        npm ERR!         node_modules/react-apollo
    remote:        npm ERR!       1 more (react-apollo)
    remote:        npm ERR!     @apollo/react-common@"^3.1.4" from @apollo/react-hoc@3.1.5
    remote:        npm ERR!     node_modules/@apollo/react-hoc
    remote:        npm ERR!       @apollo/react-hoc@"^3.1.5" from react-apollo@3.1.5
    remote:        npm ERR!       node_modules/react-apollo
    remote:        npm ERR!         react-apollo@"^3.1.3" from the root project
    remote:        npm ERR!     3 more (@apollo/react-hooks, @apollo/react-ssr, react-apollo)
    remote:        npm ERR!   14 more (@apollo/react-components, @apollo/react-hoc, ...)
    remote:        npm ERR! 
    remote:        npm ERR! Could not resolve dependency:
    remote:        npm ERR! peer react@"^17.0.2 || ^18.0.0-0" from next@12.1.6
    remote:        npm ERR! node_modules/next
    remote:        npm ERR!   next@"^12.1.6" from the root project
    remote:        npm ERR!   peer next@">= 5.1.0" from next-env@1.1.1
    remote:        npm ERR!   node_modules/next-env
    remote:        npm ERR!     next-env@"^1.1.0" from the root project
    remote:        npm ERR! 
    remote:        npm ERR! Conflicting peer dependency: react@18.1.0
    remote:        npm ERR! node_modules/react
    remote:        npm ERR!   peer react@"^17.0.2 || ^18.0.0-0" from next@12.1.6
    remote:        npm ERR!   node_modules/next
    remote:        npm ERR!     next@"^12.1.6" from the root project
    remote:        npm ERR!     peer next@">= 5.1.0" from next-env@1.1.1
    remote:        npm ERR!     node_modules/next-env
    remote:        npm ERR!       next-env@"^1.1.0" from the root project
    remote:        npm ERR! 
    remote:        npm ERR! Fix the upstream dependency conflict, or retry
    remote:        npm ERR! this command with --force, or --legacy-peer-deps
    remote:        npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
    remote:        npm ERR! 
    remote:        npm ERR! See /tmp/npmcache.KnKS4/eresolve-report.txt for a full report.
    remote:        
    remote:        npm ERR! A complete log of this run can be found in:
    remote:        npm ERR!     /tmp/npmcache.KnKS4/_logs/2022-06-03T12_47_36_545Z-debug-0.log
    remote: 
    remote: -----> Build failed
Run Code Online (Sandbox Code Playgroud)

Cua*_*ado 8

将环境变量添加NPM_CONFIG_LEGACY_PEER_DEPS到您的 Heroku 应用程序并将其值设置为true在此输入图像描述


小智 5

几天前(六月初)我在 Heroku 上部署 React 应用程序时也遇到了同样的问题。看来这个问题是npm版本更新引起的。默认情况下,Heroku 使用最新稳定版本的 Node 和 npm 作为构建引擎,但如果您使用它们的早期版本,可能会导致依赖项冲突。

因此,如果它在本地工作完全正常,但在 Heroku 上部署时发生此问题,则解决方案如下:

使用node --versionnpm --version检查本地实例上的版本,然后将它们添加到 package.json 文件的引擎部分下,如下所示(将 16.0.0 和 7.10.0 替换为您拥有的版本):

"engines": {
    "node": "16.0.0",
    "npm": "7.10.0"
},
Run Code Online (Sandbox Code Playgroud)

然后在 Heroku 上重新部署该应用程序。问题应该得到解决。