rogeriochaves / npm-force-resolutions

Force npm to install a specific transitive dependency version
567 stars 28 forks source link

Broken with NPM >= 8.6.0 #64

Closed Strato closed 2 years ago

Strato commented 2 years ago

Hello,

I've switched to Node 16.15.1 on my machine, which uses NPM 8.11.0, and I have this error when I run rm -rf **/node_modules && npm i && npx lerna bootstrap :

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: apollo-metrics@1.0.1
npm ERR! Found: prom-client@13.2.0
npm ERR! node_modules/prom-client
npm ERR!   prom-client@"13.2.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer prom-client@"^11.5.3" from apollo-metrics@1.0.1
npm ERR! node_modules/apollo-metrics
npm ERR!   apollo-metrics@"^1.0.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: prom-client@11.5.3
npm ERR! node_modules/prom-client
npm ERR!   peer prom-client@"^11.5.3" from apollo-metrics@1.0.1
npm ERR!   node_modules/apollo-metrics
npm ERR!     apollo-metrics@"^1.0.1" 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.

(for the record, both apollo-metrics and prom-client are old dependencies which I haven't touched for the past 10 months)

It happens when Lerna get to the point of installing a sub-package of my repo which uses npm-force-resolutions as pre-install. The logs show that npx npm-force-resolutions is the command that leads to the error.

This is related to this issue on the NPM repo, which describes a new behavior of NPM (considered a """feature""") introduced in NPM 8.6.0.

I think you should take a look at it since it seems to break the use of npm-force-resolutions.

Strato commented 2 years ago

If I remove "preinstall": "npx npm-force-resolutions" from the sub-package's package.json I get the same error, so this is not related to npm-force-resolutions. Sorry.

Strato commented 2 years ago

For the record, I added this in my lerna.json config file:

"npmClientArgs": ["--legacy-peer-deps"],

But now I have the following error Invalid version: ^6.2.0 which boils down to this:

"resolutions": {
    "fs-capacitor": "^6.2.0"
}

It seems to come from the ^. If I remove it the installation works but my app is broken.