You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice an important fact: the dependencies.app.requires.lib field, with value file:lib, contains a path relative to the root of the tree. However, in package.json, the same dependency is specified relative to the requesting package's directory, i.e., file:../lib. We'll later see that this difference between package-lock.json and package.json formats is not correctly handled.
Now, with the lockfile present, delete the node_modules directory, and run npm install again. This time, it runs with no node_modules (i.e., empty currentTree), and installs from lockfile (unlike the first run)
Expected result:
The node_modules folder is the same as in the previous run, i.e., contains two symlinks to ../app and ../lib.
Actual result:
The node_modules folder contains only the app -> ../app symlink. The lib -> ../lib one is not present at all. npm install incorrectly determined that it's extraneous (not required by anyone) and prunes it (in pruneIdealTree)
See also:
To see a real-world example in a widely used project, just check out the lerna repo and run npm install there. Then, running npm ls reports a lot of missing package links:
npm ERR! missing: @lerna/cli@file:../../core/cli, required by @lerna-test/command-runner@0.0.0-test-only
npm ERR! missing: @lerna/package@file:../../core/package, required by @lerna-test/pkg-matchers@0.0.0-test-only
npm ERR! missing: @lerna/get-packed@file:../get-packed, required by @lerna/pack-directory@3.10.5
[...]
The text was updated successfully, but these errors were encountered:
Fix: #43
This fixes the bug identified by npm/cli#750
Link deps that point to a location underneath the root package are fully
resolved and reified. Links external to the root path are left alone,
because they exist in a different project and presumably have their own
dep resolution being done separately.
Steps to reproduce
Create a monorepo-style project with the following structure:
/package.json
/app/package.json
/lib/package.json
There's a root package that depends on
./app
which in turn depends on../lib
.Now run
npm install
. That will produce anode_modules
folder with two symlinks:and a lockfile with this content:
Notice an important fact: the
dependencies.app.requires.lib
field, with valuefile:lib
, contains a path relative to the root of the tree. However, inpackage.json
, the same dependency is specified relative to the requesting package's directory, i.e.,file:../lib
. We'll later see that this difference betweenpackage-lock.json
andpackage.json
formats is not correctly handled.Now, with the lockfile present, delete the
node_modules
directory, and runnpm install
again. This time, it runs with nonode_modules
(i.e., emptycurrentTree
), and installs from lockfile (unlike the first run)Expected result:
The
node_modules
folder is the same as in the previous run, i.e., contains two symlinks to../app
and../lib
.Actual result:
The
node_modules
folder contains only theapp -> ../app
symlink. Thelib -> ../lib
one is not present at all.npm install
incorrectly determined that it's extraneous (not required by anyone) and prunes it (inpruneIdealTree
)See also:
To see a real-world example in a widely used project, just check out the
lerna
repo and runnpm install
there. Then, runningnpm ls
reports a lot of missing package links:The text was updated successfully, but these errors were encountered: