Skip to content

[BUG] --install-links fails when local package has nested local dependencies #8342

Open
@u1f992

Description

@u1f992

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 installing a local package with --install-links, if that package has its own local dependencies, the installation fails. Is this behavior by design?

In this example, package b depends on package a, both located in sibling directories:

$ tree . -I node_modules
.
├── a
│   ├── package-lock.json
│   └── package.json
├── b
│   ├── package-lock.json
│   └── package.json
└── mainpkg
    ├── package-lock.json
    └── package.json

4 directories, 6 files

$ cat b/package.json 
{"name":"b","dependencies":{"a":"file:../a"}}

The npm CLI attempts to resolve ../a from within node_modules/b or node_modules/a, which does not exist. This results in an ENOENT error:

$ cd mainpkg && npm install --install-links ../b
npm error code ENOENT
npm error syscall open
npm error path /home/mukai/Documents/mainpkg/node_modules/a/package.json
npm error errno -2
npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/home/mukai/Documents/mainpkg/node_modules/a/package.json'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
npm error A complete log of this run can be found in: /home/mukai/.npm/_logs/2025-06-03T11_28_04_990Z-debug-0.log

Expected Behavior

The dependency a, as listed in b's package.json, should be resolved relative to b itself (i.e., ../a from b). As a result, the structure of mainpkg/node_modules should look like this:

$ tree mainpkg/node_modules
mainpkg/node_modules
├── a -> ../../a
└── b -> ../../b

3 directories, 0 files

Steps To Reproduce

$ mkdir a b mainpkg
$ echo '{"name":"a"}' > a/package.json
$ echo '{"name":"b"}' > b/package.json
$ cd b && npm install ../a && cd ../
$ cd mainpkg && npm init --yes
$ npm install --install-links ../b

Environment

  • npm: 11.4.1
  • Node.js: v22.14.0
  • OS Name: Ubuntu 24.04
  • System Model Name: ThinkPad-X1-Carbon-7th
  • npm config:
; "user" config from /home/mukai/.npmrc

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

; node bin location = /home/mukai/.nvm/versions/node/v22.14.0/bin/node
; node version = v22.14.0
; npm local prefix = /home/mukai/Documents/mainpkg
; npm version = 11.4.1
; cwd = /home/mukai/Documents/mainpkg
; HOME = /home/mukai
; 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