cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm possibly installs wrong dependencies

Open doberkofler opened this issue 11 months ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

Based on the discussion with the maintainer of the typescript-eslint project in the SR https://github.com/typescript-eslint/typescript-eslint/issues/8732, npm 10.5.0 wrongly resolves a dependency.

If you check the version listed in ./node_modules/@typescript-eslint/utils/package.json it should be v7 If it's v5 then double check ./node_modules/typescript-eslint - it should contain its own ./node_modules/@typescript-eslint/utils which is v7. If you don't have a v7 version of the utils package - then that's the cause - npm is doing the wrong thing.

Expected Behavior

No response

Steps To Reproduce

Install:

{
	"name": "test",
	"type": "commonjs",
	"devDependencies": {
		"@eslint/js": "8.57.0",
		"cross-env": "7.0.3",
		"eslint": "8.57.0",
		"eslint-plugin-jest": "27.9.0",
		"typescript": "5.4.2",
		"typescript-eslint": "7.3.1"
	}
}

Environment

  • npm: 10.5.0
  • Node.js: 20.11.0
  • OS Name: macOS
  • System Model Name: Macbook Pro
  • npm config:
//registry.npmjs.org/:_authToken = (protected)
audit = false
fund = false

doberkofler avatar Mar 20 '24 05:03 doberkofler

@doberkofler I tried to replicate the issue and ran npm ls @typescript-eslint/utils which appears to be correct and looks like it's not a problem with npm.

└─┬ [email protected]
  ├─┬ @typescript-eslint/[email protected]
  │ ├─┬ @typescript-eslint/[email protected]
  │ │ └── @typescript-eslint/[email protected]
  │ └── @typescript-eslint/[email protected]
  └── @typescript-eslint/[email protected]

milaninfy avatar Mar 20 '24 15:03 milaninfy

What you've got is the following:

So we can see that @typescript-eslint/[email protected] is depended on twice and `@typescript-eslint/utils@^5.10.0 is depended on once.

So I would expect an install that looks like this:

I.e. Npm installs the most commonly depended on version at the root to have the smallest install.

But instead you get this install:

I.e. Npm has installed a the lest commonly depended on version at the root and has the largest install.

This seems like incorrect behaviour - npm is preferring the install with most duplication by default.

For comparison:

  • [email protected] installs the second, deduplicated install
  • [email protected] (with nodeLinker: node-modules) installs the second, deduplicated install
  • [email protected]
    • with node-linker=hoisted - installs the second, deduplicated install
    • with node-linker=isolated - installs the first, duplicated install

bradzacher avatar Mar 20 '24 21:03 bradzacher