简体   繁体   English

Heroku Shopify 应用程序错误 'npm ERR! ERESOLVE 无法解析依赖树'

[英]Heroku Shopify Application Error 'npm ERR! ERESOLVE unable to resolve dependency tree'

Greetings I have a problem with Heroku because it's don't want to install legacy packages for my Shopify app, my Shopify app is on Github and I just set up everything that my application needs, but when I deploy the main branch on Heroku I get this error in Heroku console below, can someone help me fix this?问候 我对 Heroku 有疑问,因为它不想为我的 Shopify 应用程序安装遗留软件包,我的 Shopify 应用程序在 Github 上,我只是设置了我的应用程序所需的一切,但是当我在 Heroku 上部署主分支时,我得到下面 Heroku 控制台中的这个错误,有人可以帮我解决这个问题吗?

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/nodejs
-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       USE_NPM_INSTALL=true
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=false
       
-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)
       
       Resolving node version 16.x...
       Downloading and installing node 16.14.0...
       Using default npm version: 8.3.1
       
-----> Restoring cache
       Caching has been disabled because NODE_MODULES_CACHE=false
       
-----> Installing dependencies
       Installing node modules (package.json + package-lock)
       npm ERR! code ERESOLVE
       npm ERR! ERESOLVE unable to resolve dependency tree
       npm ERR! 
       npm ERR! While resolving: shopify-app-node@1.0.0
       npm ERR! Found: react@16.14.0
       npm ERR! node_modules/react
       npm ERR!   react@"^16.10.1" from the root project
       npm ERR! 
       npm ERR! Could not resolve dependency:
       npm ERR! peer react@"^17.0.2 || ^18.0.0-0" from next@12.0.10
       npm ERR! node_modules/next
       npm ERR!   next@"^12.0.2" 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 /tmp/npmcache.CTfHl/eresolve-report.txt for a full report.
       
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /tmp/npmcache.CTfHl/_logs/2022-02-10T12_18_50_156Z-debug-0.log
-----> Build failed
       
       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys
       
       Some possible problems:
       
       - Node version not specified in package.json
         https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

My package.json我的 package.json

{
  "name": "shopify-app-node",
  "version": "1.0.0",
  "description": "Shopify's node app for CLI tool",
  "scripts": {
    "test": "jest",
    "dev": "cross-env NODE_ENV=development nodemon ./server/index.js --watch ./server/index.js",
    "build": "NEXT_TELEMETRY_DISABLED=1 next build",
    "start": "cross-env NODE_ENV=production node ./server/index.js"
  },
  "engines": {
    "node": "16.14.0",
    "npm": "8.4.1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Shopify/shopify-app-node.git"
  },
  "author": "Shopify Inc.",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/shopify/shopify-app-node/issues"
  },
  "dependencies": {
    "@babel/core": "7.12.10",
    "@babel/polyfill": "^7.6.0",
    "@babel/preset-env": "^7.12.11",
    "@babel/register": "^7.12.10",
    "@shopify/app-bridge-react": "^2.0.2",
    "@shopify/app-bridge-utils": "^2.0.2",
    "@shopify/koa-shopify-auth": "^4.1.2",
    "@shopify/polaris": "^6.2.0",
    "apollo-boost": "^0.4.9",
    "axios": "^0.25.0",
    "cross-env": "^7.0.3",
    "dotenv": "^8.2.0",
    "graphql": "^14.5.8",
    "isomorphic-fetch": "^3.0.0",
    "koa": "^2.13.1",
    "koa-bodyparser": "^4.3.0",
    "koa-compress": "^5.1.0",
    "koa-cors": "0.0.16",
    "koa-logger": "^3.2.1",
    "koa-router": "^10.0.0",
    "koa-session": "^6.1.0",
    "mysql2": "^2.3.3",
    "next": "^12.0.2",
    "next-env": "^1.1.0",
    "node-fetch": "^2.6.7",
    "react": "^16.10.1",
    "react-apollo": "^3.1.3",
    "react-dom": "^16.10.1",
    "sequelize": "^6.13.0",
    "slugify": "^1.6.5",
    "validator": "^13.7.0",
    "webpack": "^4.44.1"
  },
  "devDependencies": {
    "@babel/plugin-transform-runtime": "^7.12.10",
    "@babel/preset-stage-3": "^7.0.0",
    "babel-jest": "26.6.3",
    "babel-register": "^6.26.0",
    "enzyme": "3.11.0",
    "enzyme-adapter-react-16": "1.15.6",
    "husky": "^4.3.6",
    "jest": "26.6.3",
    "lint-staged": "^10.5.4",
    "nodemon": "^2.0.7",
    "prettier": "2.2.1",
    "react-addons-test-utils": "15.6.2",
    "react-test-renderer": "16.14.0"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js,css,json,md}": [
      "prettier --write"
    ]
  }
}

If you cannot reproduce locally, set package.json engines: to match your local development如果本地无法复现,设置 package.json engines:匹配本地开发

This is not the OP's exact issue as they had specified engines: and reproduced locally, so definitely what they needed was to resolve it locally first, which is a subset of the infinite Unable to resolve dependency tree error when installing npm packages这不是 OP 的确切问题,因为他们指定了engines:并在本地复制,所以他们肯定需要先在本地解决它,这是安装 npm 包时无限无法解析依赖树错误的子集

But I couldn't reproduce locally even after delting node_modules and package-lock.json , so as soon as I set engines: , which Heroku respects , to match my local working setup node --version and npm --version with:但是即使在删除node_modulespackage-lock.json之后我也无法在本地复制,所以一旦我设置了Heroku 尊重engines:以匹配我的本地工作设置node --versionnpm --version

  "engines": {
    "node": "14.17.0",
    "npm": "6.14.13"
  },

it started working on Heroku.它开始在 Heroku 上工作。 Here's my failing package.json to which the engines were added.这是添加了engines的失败的package.json The error was:错误是:

remote:        Installing node modules (package.json)                                                                                                                                                                                                                           
remote:        npm ERR! code ERESOLVE                                                                                                                                                                                                                                           
remote:        npm ERR! ERESOLVE unable to resolve dependency tree                                                                                                                                                                                                              
remote:        npm ERR!                                                                                                                                                                                                                                                         
remote:        npm ERR! While resolving: conduit-node@1.0.0                                                                                                                                                                                                                     
remote:        npm ERR! Found: react@17.0.2                                                                                                                                                                                                                                     
remote:        npm ERR! node_modules/react                                                                                                                                                                                                                                      
remote:        npm ERR!   react@"17.0.2" from the root project                                                                                                                                                                                                                  
remote:        npm ERR!                                                                                                                                                                                                                                                         
remote:        npm ERR! Could not resolve dependency:                                                                                                                                                                                                                           
remote:        npm ERR! peer react@"^16.11.0" from swr@0.3.0                                                                                                                                                                                                                    
remote:        npm ERR! node_modules/swr                                                                                                                                                                                                                                        
remote:        npm ERR!   swr@"0.3.0" from the root project

Prior to the fix, Heroku logs show it was using:在修复之前,Heroku 日志显示它正在使用:

remote:        Downloading and installing node 16.14.0...                                                                                                                                                                                                                       
remote:        Using default npm version: 8.3.1

For this reason, you should Always, Always, set engines to match your local setup on a Heroku project.出于这个原因,您应该始终、始终设置engines以匹配您在 Heroku 项目中的本地设置。

Ciro Santilli's way solved my problem: Ciro Santilli 的方式解决了我的问题:

I added these lines to package.json and the problem fixed:我将这些行添加到 package.json 并修复了问题:

  "engines": {
    "node": "16.x",
    "npm": "8.5.5"
  },

Apparently for me the "knex" module that I use is not compatible with newer npm (I am not sure).显然对我来说,我使用的“knex”模块与较新的 npm 不兼容(我不确定)。

You may use .npmrc你可以使用.npmrc

New versions of npm do not allow you to install dependencies with different versions of peer dependencies because it may lead to breaking change. npm 的新版本不允许您安装具有不同版本的对等依赖项的依赖项,因为这可能会导致破坏性更改。 So if you are sure that everything works without any issues, maybe you have good tests.因此,如果您确定一切正常,没有任何问题,也许您进行了良好的测试。 Just add --legacy-peer-deps or --force after your npm script (basically it's npm i ).只需在 npm 脚本之后添加--legacy-peer-deps--force (基本上是npm i )。 But it's so annoying to write it, instead you can create '.npmrc' file in the root of your project with following:但是写起来很烦人,您可以在项目的根目录中创建“.npmrc”文件,方法如下:

legacy-peer-deps=true
...

or even:甚至:

force=true
...

Now you don't need to add --legacy-peer-deps or --force manually.现在您不需要手动添加--legacy-peer-deps--force

ps.附言。 It also solves the problem with Heroku when you cannot explicitly use npm i --legacy-peer-deps .当您无法显式使用npm i --legacy-peer-deps时,它还解决了 Heroku 的问题。 At least I don't know how to do so.至少我不知道该怎么做。

  1. I install these old packages with npm install --force我使用npm install --force安装这些旧包
  2. I run npm outdated我运行npm outdated
  3. I see what packages are in red我看到什么包裹是红色的
  4. I do upgrade from the current version to the wanted version with npm install --save packagename@wanted_version我使用npm install --save packagename@wanted_version从当前版本升级到想要的版本
  5. Remove any empty files that you may have in your project删除项目中可能存在的任何空文件
  6. Uploaded to git上传到 git
  7. Deploy to Heroku部署到 Heroku

I found a solution.我找到了解决办法。 You can add config variables in Heroku apps.您可以在 Heroku 应用程序中添加配置变量。

Go to the app in Heroku -> settings -> Reveal Config Vars Go 到 Heroku 中的应用程序 -> 设置 -> 显示配置变量

Add a new config var with the key: NPM_CONFIG_LEGACY_PEER_DEPS and value true , and then redeploy.使用键添加一个新的配置变量: NPM_CONFIG_LEGACY_PEER_DEPS和值true ,然后重新部署。

Your lock file contains conflicting dependencies.您的锁定文件包含冲突的依赖项。 Since you were able to reproduce the error locally using npm ci we have a good way to test a fix locally.由于您能够使用npm ci在本地重现错误,因此我们有一种在本地测试修复的好方法。

It looks like you are depending directly on React 16. Is that something that you need directly, or is it just a dependency for Next.js?看起来您直接依赖于 React 16。这是您直接需要的东西,还是只是 Next.js 的依赖项?

If it's not something you need directly, upgrade it per the Next.js docs :如果它不是您直接需要的东西,请按照 Next.js 文档对其进行升级

npm install react@latest react-dom@latest

That should modify your package-lock.json .那应该修改你的package-lock.json Then try installing from the lock file again with npm ci .然后尝试使用npm ci从锁定文件再次安装。 If that fixes things, commit the change and redeploy.如果这样可以解决问题,请提交更改并重新部署。

On the other hand, if you are directly depending on React 16 and cannot upgrade you'll have to consider rolling back to an earlier version of Next.js.另一方面,如果你直接依赖 React 16 并且无法升级,你将不得不考虑回滚到 Next.js 的早期版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM