npm install causes Cannot read property 'name' of undefined

Viewed 4346

I run npm i and got this message:

npm i
npm ERR! Cannot read property 'name' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/minta-dan/.npm/_logs/2021-02-01T12_07_22_367Z-debug.log

in the log I can tell that everything installed but:

619 timing idealTree Completed in 47459ms
4620 timing command:install Completed in 47463ms
4621 verbose stack TypeError: Cannot read property 'name' of undefined
4621 verbose stack     at Arborist.[canPlaceDep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1387:62)
4621 verbose stack     at Arborist.[placeDep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1061:36)
4621 verbose stack     at Arborist.[placeDep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1212:41)
4621 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:766:46
4 Answers

I ran into this when trying to run npm install on a project with a yarn.lock file. If that's your situation, I suggest you run yarn install instead or do the conversion

I had this same problem not running npm i but while installing the ycm-core/YouCompleteMe plugin for vim. Running npm install -g npm@latest didn't solve the issue. But it stopped occurring only when I changed the 'global' default to false in file ~/.nmprc:

global=false

Before that, I updated all global packages without success:

npm -g outdated
npm -g update

I learned that maybe it is a good idea to use global only when required with '-g' flag.

I've got the same error, but for me, the solution was the rollback of npm to the 7.0.0 version (from the latest - 7.17.0).

Related