cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] ERESOLVE unable to resolve dependency tree

Open abdusamadtv opened this issue 5 years ago • 7 comments

Current Behavior:

Getting ERESOLVE unable to resolve dependency tree error while installing dependencies

Expected Behavior:

Successful installation of dependencies

Steps To Reproduce:

rm -rf node_modules package-lock.json

Environment:

  • OS: macOS Big Sur 11.2.3 (20D91)
  • Node: 16.0.0
  • npm: 7.10.0

Error

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: [email protected]
npm ERR! node_modules/pg
npm ERR!   pg@"^8.0.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional pg@"^7.18.2" from [email protected]
npm ERR! node_modules/knex
npm ERR!   knex@"^0.20.14" from the root project
npm ERR!   peer knex@"<0.95.0" from [email protected]
npm ERR!   node_modules/objection
npm ERR!     objection@"^2.1.3" 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 /Users/abdusamad/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/abdusamad/.npm/_logs/2021-04-21T05_30_29_351Z-debug.log

package.json

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "commonjs",
  "engines": {
    "node": ">=12.16.2"
  },
  "scripts": {
    "migrate": "knex migrate:latest",
    "lint": "eslint ./ --fix",
    "dev": "nodemon src/index.js",
    "start": "node src/index.js",
    "postinstall": "link-module-alias",
    "preinstall": "command -v link-module-alias && link-module-alias clean || true"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.19.2",
    "bcrypt": "^4.0.1",
    "cron": "^1.8.2",
    "currency-codes": "^2.1.0",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "iconv-lite": "^0.6.2",
    "jsonwebtoken": "^8.5.1",
    "knex": "^0.20.14",
    "link-module-alias": "^1.2.0",
    "moment": "^2.24.0",
    "mongoose": "^5.9.10",
    "morgan": "^1.10.0",
    "nodemon": "^2.0.3",
    "objection": "^2.1.3",
    "oracledb": "^4.2.0",
    "p-limit": "^3.0.2",
    "pg": "^8.0.2",
    "rotating-file-stream": "^2.1.3",
    "uuid": "^7.0.3",
    "xml2js": "^0.4.23"
  },
  "devDependencies": {
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.10.1",
    "eslint-plugin-prettier": "^3.1.3",
    "prettier": "^2.0.4"
  },
  "_moduleAliases": {
    "~root": "./"
  }
}

abdusamadtv avatar Apr 21 '21 05:04 abdusamadtv

The error message tells you the problem: namely, that you depend on pg v8, but the version of knex you're using requires pg 7. This means your dependency graph is invalid.

You need to either downgrade pg to v7, or upgrade knex to a version that peerDepends on pg v8.

ljharb avatar Apr 21 '21 05:04 ljharb

The error message tells you the problem: namely, that you depend on pg v8, but the version of knex you're using requires pg 7. This means your dependency graph is invalid.

You need to either downgrade pg to v7, or upgrade knex to a version that peerDepends on pg v8.

Then why does everything work when I switch to Node.js v14.16.1 and npm v6.14.12?

abdusamadtv avatar Apr 21 '21 05:04 abdusamadtv

It doesn't actually work - it's just that npm 6 doesn't tell you during installs that your dep graph is invalid. Run npm ls, and you'll see it exit nonzero.

When your dep graph is invalid, things might work, but you can't rely on that.

ljharb avatar Apr 21 '21 06:04 ljharb

Same problem for me.

cdupetit avatar Apr 21 '21 07:04 cdupetit

I have faced the same issue. As a quick fix, I had to downgrade to npm version 6.

Other solution would be to use '--legacy-peer-deps' flag.

arjunsatyanandaraju avatar Apr 22 '21 10:04 arjunsatyanandaraju

The proper fix is to make your dep graph valid. Downgrading to npm 6, or using the legacy flag, just hides that your program (not npm) is broken.

If the peer dep error message isn’t clear to anyone, please post it - I’m happy to decipher it.

@abdusamadtv does fixing the invalid combo with pg help?

ljharb avatar Apr 22 '21 14:04 ljharb

As @ljharb has noted, you must resolve the conflict in your peer dependencies to resolve this problem; There's options to work around this (ie. --force or --legacy-peer-deps) as well.

darcyclarke avatar Jun 04 '21 18:06 darcyclarke