npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.48k stars 3.17k forks source link

[BUG] ERESOLVE unable to resolve dependency tree #3113

Closed abdusamadtv closed 3 years ago

abdusamadtv commented 3 years ago

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:

Error

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: pg@8.6.0
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 knex@0.20.15
npm ERR! node_modules/knex
npm ERR!   knex@"^0.20.14" from the root project
npm ERR!   peer knex@"<0.95.0" from objection@2.2.15
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": "./"
  }
}
ljharb commented 3 years ago

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.

abdusamadtv commented 3 years ago

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?

ljharb commented 3 years ago

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.

cdupetit commented 3 years ago

Same problem for me.

arjunsatyanandaraju commented 3 years ago

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.

ljharb commented 3 years ago

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?

darcyclarke commented 3 years ago

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.