npm install fails to install all dependencies, and installing specific dependency fails with npm error.
npm ERR! Cannot read property 'version' of undefined
From log:
71 verbose stack TypeError: Cannot read property 'version' of undefined
71 verbose stack at Arborist.[saveIdealTree] (/home/node-15/.nvm/versions/node/v15.0.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:800:33)
71 verbose stack at /home/node-15/.nvm/versions/node/v15.0.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:124:39
71 verbose stack at async Arborist.reify (/home/node-15/.nvm/versions/node/v15.0.0/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:121:5)
71 verbose stack at async install (/home/node-15/.nvm/versions/node/v15.0.0/lib/node_modules/npm/lib/install.js:40:5)
Npm installs all dependencies, and npm install typescript
works.
git clone https://github.com/hapijs/lab.git && cd lab
npm install
npm install typescript
While it this issue could be similar to the one in #1998, it appears to be unique since this fails a direct install. Also, if I remove the peerDependenciesMeta
entry from package.json
, it will work as expected.
It is interesting that the result depends on a third-party package.json property, which npm does not officially support. At least according to https://github.com/npm/cli/blob/v7.0.3/docs/content/configuring-npm/package-json.md.
@kanongil npm definitely officially supports peerDependenciesMeta, it just appears to be missing from the docs.
The issue here is that, while we do install peerDependencies
by default, we _don't_ install _optional_ peerDependencies
, as those are used more for plugins and typically the user does not wish for them to be installed.
We do officially support the peerDependenciesMeta[pkgname].optional
boolean, but the docs are lagging behind the code, unfortunately. They'll be updated ahead of moving v7.0.0 to GA status on the latest
dist-tag.
What's happening here is that we're loading the peer edge ahead of the dev edge, and then skipping it. And since the peer edge is optional, we don't install it. For the root project at least, dev
should take priority, I agree, so this is a bug.
Also, even if it's _not_ a dev dependency, if you explicitly tell it to install a package, it should do that, even if it's an optional peer.
So, two bugs :)