Skip to content

[BUG] running npm install has nondeterministic behaviour and race conditions for packages with link references #8201

@domdomegg

Description

@domdomegg

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

This happens when a package ('packageA') has a link to a dependency bundled within itself ('packageB'). This results in a condition when reifying the tree where:

  • if 'packageA' is installed before packageB, the files for packageB exist and the link is created successfully
  • otherwise, the link silently fails to create

Because both packageA and packageB are installed in a Promise.all(), there is a race where either one of these can happen first, resulting in nondeterministic behaviour.

I discovered this as I was trying to fix #8199. This blocks us from erroring when a link target does not exist, because at the point of reifying we can't easily tell if the link target doesn't exist because it depends on another package, or because it just doesn't exist.

Expected Behavior

The packages should be installed probably in dependency order, e.g. if packageB is a local file and part of packageA, it should wait for packageA to complete installing.

OR

External packages relying on local file links should just not be supported as a feature, if it is too unstable/causes performance issues.

Steps To Reproduce

npm init
npm install @isaacs/testing-link-dep

(notice that probably your node_modules will now not have a linked-dep link, and this will have silently failed to create)

npm install

(notice that probably your node_modules will now have a linked-dep link)

You can also then remove node_modules and run npm install multiple times to see the race condition.

Environment

  • npm: 11.2.0 (present on latest branch)
  • Node.js: v23.10.0
  • OS Name: macOS
  • System Model Name: macOS
  • npm config:
; "builtin" config from /opt/homebrew/lib/node_modules/npm/npmrc

prefix = "/opt/homebrew"

; "user" config from /Users/adam/.npmrc

//registry.npmjs.org/:_authToken = (protected)

; node bin location = /opt/homebrew/Cellar/node/23.10.0_1/bin/node
; node version = v23.10.0
; npm local prefix = /Users/adam
; npm version = 11.2.0
; cwd = /Users/adam
; HOME = /Users/adam
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions