Cli: [BUG] hapijs/lab repo fails to install

Created on 21 Oct 2020  路  4Comments  路  Source: npm/cli

Current Behavior:

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)

Expected Behavior:

Npm installs all dependencies, and npm install typescript works.

Steps To Reproduce:

git clone https://github.com/hapijs/lab.git && cd lab
npm install
npm install typescript

Environment:

  • Node: 15.0.0
  • npm: 7.0.2
Bug Release 7.x

All 4 comments

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 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

darcyclarke picture darcyclarke  路  3Comments

ahuglajbclajep picture ahuglajbclajep  路  3Comments

darcyclarke picture darcyclarke  路  3Comments

jaydenseric picture jaydenseric  路  3Comments

dr-js picture dr-js  路  3Comments