npm install for package with local dependency fails

I’m using 6.6.0-next.1 and I still can’t install local dependencies.
Here is a minimal repo showing the problem: https://github.com/baptistemarchand/npm-local-path-bug-repro
I have two packages A and B.
A depends on B, using a local path (file:../).
B depends on left-pad (sorry :blush: ).

.
β”œβ”€β”€ a
β”‚   β”œβ”€β”€ package-lock.json
β”‚   └── package.json
└── b
    └── package.json

When I run npm install in package A it succeeds (there are no errors), the symlink to package B is created in node_modules (as expected) but the dependencies of B are not installed. The tree now looks like this :

..
β”œβ”€β”€ a
β”‚   β”œβ”€β”€ node_modules
β”‚   β”‚   └── b -> ../../b
β”‚   β”œβ”€β”€ package-lock.json
β”‚   └── package.json
└── b
    └── package.json

If I use npm ci instead of npm install it works as expected, producing the following tree:

.
β”œβ”€β”€ a
β”‚   β”œβ”€β”€ node_modules
β”‚   β”‚   └── b -> ../../b
β”‚   β”œβ”€β”€ package-lock.json
β”‚   └── package.json
└── b
    β”œβ”€β”€ node_modules
    β”‚   └── left-pad
    β”‚       β”œβ”€β”€ ....
    └── package.json

It also installs correctly if I remove the package-lock.json in package A.

Am I right to think that this is caused by the same bug discussed above?

Thank you for your help.

4 Likes

Any news on a fix for this? I too can reproduce this.

2 Likes

I am still hitting this error on Travis builds when using file: dependencies, and always hit it locally on subsequent npm installs as well. Looking around it seems like this has been an issue for over a year – is this slated to be fixed?

Hi! I have a similar problem (I think).

I have a project A that depends of a package B using local path (file:…). And package B has also some locals dependencies on packages C and D also with local path (file:…) something like:

β”œβ”€β”€ a
    └── package.json
         └── "b": "file:packages/b.tgz"
             └── package.json
                └── "c": "file:modules/c.tgz"
                └── "d": "file:modules/d.tgz"

I’ve tried removing all: package-lock.json, node_modules, clear npm cache, and nothing seems to work. I keep geting this error:

3037 verbose stack Error: ENOENT: no such file or directory, stat 'C:\xampp\htdocs\test-module\packages\b.tgz\modules\c.tgz'
3038 verbose cwd C:\xampp\htdocs\test-module
3039 verbose Windows_NT 10.0.17134
3040 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\abcd\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install"
3041 verbose node v8.12.0
3042 verbose npm  v6.9.0
3043 error path C:\xampp\htdocs\test-module\packages\b.tgz\modules\c.tgz
3044 error code ENOENT
3045 error errno -4058
3046 error syscall stat
3047 error enoent ENOENT: no such file or directory, stat 'C:\xampp\htdocs\test-module\packages\b.tgz\modules\c.tgz'
3048 error enoent This is related to npm not being able to find a file.
3049 verbose exit [ -4058, true ]

Any help?
Thanks :slight_smile:

While I can neither confirm or deny if the original issue has been resolved, I can confirm that on npm v6.9.0, the issue persists if the dependency has a symlink in its path.

8771 verbose stack Error: ENOENT: no such file or directory, rename '/Users/sohrab/workspaces/myworkspace/myapp/server/node_modules/.staging/@company/fastify-openapi-cfdde382/node_modules/@babel/cli' -> '/Users/sohrab/workspaces/myworkspace/myapp/server/node_modules/.staging/@babel/cli-e2c46704'
8772 verbose cwd /Users/sohrab/workspaces/myworkspace/myapp/server
8773 verbose Darwin 18.5.0
8774 verbose argv "/Users/sohrab/.nvm/versions/node/v10.15.3/bin/node" "/Users/sohrab/.nvm/versions/node/v10.15.3/bin/npm" "update" "nyc" "mocha"
8775 verbose node v10.15.3
8776 verbose npm  v6.9.0
8777 error path /Users/sohrab/workspaces/myworkspace/myapp/server/node_modules/.staging/@company/fastify-openapi-cfdde382/node_modules/@babel/cli
8778 error code ENOENT
8779 error errno -2
8780 error syscall rename
8781 error enoent ENOENT: no such file or directory, rename '/Users/sohrab/workspaces/myworkspace/myapp/server/node_modules/.staging/@company/fastify-openapi-cfdde382/node_modules/@babel/cli' -> '/Users/sohrab/workspaces/myworkspace/myapp/server/node_modules/.staging/@babel/cli-e2c46704'
8782 error enoent This is related to npm not being able to find a file.
8783 verbose exit [ -2, true ]

When using file: dependency to a symlink directory:

....
"dependencies": {
    "@company/fastify-openapi": "file:../fastify-openapi",
...

My current workaround is to keep deleting package-lock.json.