npm / npm/cli

[BUG] `npm i` infinite recursion with local dependencies

Open
#5,899 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting Information Bug Needs Triage Release 9.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

When using npm@9.1.2 and adding local dependencies, npm install fails / hangs forever at idealTree:#root.

The added dependencies look like this:

  "dependencies": {
    "@org/package-one": "file:./package-one-1.0.0.tgz",
    "@org/package-two": "file:./package-two-1.0.0.tgz",
    "@org/package-three": "file:./package-three-1.0.0.tgz",
    "@org/package-four": "file:./package-four-1.0.0.tgz",
    "@org/package-five": "file:./package-five-1.0.0.tgz"
  },

The logs generated using npm i --verbose look like this:

1444 silly placeDep ROOT @org/package-one@1.0.0 REPLACE for:  want: file:/Users/user/project-root/packages/package-one
1445 silly placeDep ROOT @org/package-two@1.0.0 REPLACE for:  want: file:/Users/user/project-root/packages/package-two
1446 silly placeDep ROOT @org/package-three@1.0.0 REPLACE for:  want: file:/Users/user/project-root/packages/package-three
1447 silly placeDep ROOT @org/package-four@1.0.0 REPLACE for:  want: file:/Users/user/project-root/packages/user/backend/accessor
1448 silly placeDep ROOT @org/package-five@1.0.0 REPLACE for:  want: file:/Users/user/project-root/packages/user/backend/models
1449 timing idealTree:#root Completed in 5ms
1450 silly placeDep ROOT @org/package-one@1.0.0 REPLACE for: packages/app want: file:./package-one-1.0.0.tgz
1451 silly placeDep ROOT @org/package-two@1.0.0 REPLACE for: packages/app want: file:./package-two-1.0.0.tgz
1452 silly placeDep ROOT @org/package-three@1.0.0 REPLACE for: packages/app want: file:./package-three-1.0.0.tgz
1453 silly placeDep ROOT @org/package-four@1.0.0 REPLACE for: packages/app want: file:./package-four-1.0.0.tgz
1454 silly placeDep ROOT @org/package-five@1.0.0 REPLACE for: packages/app want: file:./package-five-1.0.0.tgz
1455 timing idealTree:packages/app Completed in 2ms

This will repeat forever. If I let npm i sit, this will print these exact same 12 lines tens of thousands of times.

Expected Behavior

Downgrading to npm@8.19.3 completely resolves the issue:

user@mbp app % npm i

added 5 packages, and audited 740 packages in 7s

103 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
Steps To Reproduce

Note that the app sits in a project that uses NPM workspaces (located at project-root).

Environment
  • npm: 9.1.2
  • Node.js: v16.14.0
  • OS Name: macOS 12.6
  • System Model Name: Macbook Pro (14-inch, 2021)
  • npm config:
npm WARN config This command does not support workspaces.
; node bin location = /usr/local/bin/node
; node version = v16.14.0
; npm local prefix = /Users/user/project-root/a
; npm version = 8.19.3
; cwd = /Users/user/cs/agym-co/a/packages/app
; HOME = /Users/user
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the npm CLI install path and the repeated idealTree:#root and packages/app log entries described in the issue. Reproduce the workspace setup with the five local .tgz dependencies under npm 9.1.2, then compare it with npm 8.19.3; done means installation completes without repeating the placement lines indefinitely.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.