cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] installing a package with incompatible peer dependencies and `--force` sometimes results in an inf. loop

Open G-Rath opened this issue 10 months ago • 4 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

On https://github.com/testing-library/eslint-plugin-jest-dom/commit/18afe30adab44a1c3fa96b9669b299178c5517b2 doing npm i eslint@9 --force results in an inf. loop outputting:

npm WARN node_modules/eslint
npm WARN   peer eslint@"^6.0.0 || ^7.0.0 || >=8.0.0" from @eslint-community/[email protected]
npm WARN   node_modules/@eslint-community/eslint-utils
npm WARN     @eslint-community/eslint-utils@"^4.2.0" from @typescript-eslint/[email protected]
npm WARN     node_modules/@typescript-eslint/utils
npm WARN     1 more (eslint)
npm WARN   17 more (@typescript-eslint/eslint-plugin, ...)
npm WARN 
npm WARN Could not resolve dependency:

Related PR: https://github.com/testing-library/eslint-plugin-jest-dom/pull/355

Expected Behavior

The install to complete fine, since I've --force'd it

Steps To Reproduce

  1. Clone https://github.com/testing-library/eslint-plugin-jest-dom
  2. Run npm i eslint@9 --force
  3. Get stuck in a loop

(also see https://github.com/testing-library/eslint-plugin-jest-dom/actions/runs/8586049626/job/23528114426?pr=355)

Environment

  • npm: 10.5.1
  • Node.js: v16.20.2 (also at least happens on 18 too)
  • OS Name: Ubuntu
  • System Model Name: -
  • npm config: -
; copy and paste output from `npm config ls` here

G-Rath avatar Apr 07 '24 04:04 G-Rath

It seems that if I remove the explicit dependency on @typescript-eslint/parser then the inf. loop is resolved even though the same resulting version of @typescript-eslint/parser is installed due to child dependencies

G-Rath avatar Apr 19 '24 20:04 G-Rath

Reproduction steps:

  1. create a new project
{
  "name": "eslint-plugin-jest-dom",
  "version": "0.1.0",
  "dependencies": {
    "@typescript-eslint/parser": "^5.9.1",
    "eslint": "^9.2.0",
    "kcd-scripts": "^12.0.0"
  }
}
  1. npm install --force
  2. npm install eslint@9 --force
  3. see the infinite logs

milaninfy avatar May 07 '24 18:05 milaninfy

~Tested against latest and this is no longer happening w/ the example repo. This was fixed by https://github.com/npm/cli/pull/7499~

Sorry, missed the eslint@9 step. This is still happening.

wraithgar avatar May 10 '24 16:05 wraithgar

The issue is in build-ideal-tree.js the buildDepStep() function is basically have code to check depsQueue if the queue has some dependency, it is recursively calling buildDepStep().. In this scenario the queue is never getting empty because of which it is going in infinite loop. Since it’s not resolving proper dependency it keeps on adding. We need to find some break conditions if someone is using --force in command.

Santoshraj2 avatar Jun 04 '24 17:06 Santoshraj2