NPM is generating the wrong path for transitive private local file system deps

What I Wanted to Do

I have private module A installed under:

~/Temp/moduleA

I have another module under ~/Repository/moduleB.

If I install ~/Temp/moduleA in an Angular App it installs fine. If I install module B in Module A, I get an error that package.json does not exist in module B.

The reason for that is that the path to module B that NPM generates is wrong. It this case it says:


npm ERR! Could not install from "../../../../Temp/Repository/moduleB" as it does not contain a package.json file.

However the path to module B should b:

npm ERR! Could not install from "../../../../Repository/moduleB" as it does not contain a package.json file.

In other words Temp should not be included.

What Happened Instead

NPM does generate the right path for the transitive dependency so it can’t load it.

NPM does generate the right path for the transitive dependency so it can’t load it.

Reproduction Steps

Create an application project and dep A and dep B and make dep A depend on dep B and then install dep A in the application project. It should generate the wrong path to dep B and say that it cant load it.

Details

Platform Info

$ npm --versions

6.9.0
$ node -p process.platform
linux

Related Stackoverflow Report

Working in Yarn

I got this working with Yarn, but Yarn uses relative paths without file: in it. Perhaps NPM could also follow this convention, so that it’s possible to switch back to NPM once this gets fixed.

Related looking existing issues: