Dmitrii Dubrovin
Dmitrii Dubrovin

Reputation: 631

NPM Cannot read property '0' of undefined

After updated Node (upto v8.6.0) and npm (upto v5.5.1) I cannot execute command npm install. After npm install I've error message:

npm ERR! Cannot read property '0' of undefined

What's trouble or I need downgrade node/npm ?

Upvotes: 47

Views: 30983

Answers (15)

Mihail Bondarenco
Mihail Bondarenco

Reputation: 61

I had a similar error caused by trying to operate on a lockfileversion 3 file using [email protected] and [email protected].

Simply upgrading these two solved it.

Upvotes: 0

gedijedi
gedijedi

Reputation: 689

What worked for me:
npm ci

Install a project with a clean slate docs: https://docs.npmjs.com/cli/v7/commands/npm-ci

Deletes node_modules and installs everything based on package-lock.json, so no need to regenerate that

Upvotes: 0

Mostafa Wael
Mostafa Wael

Reputation: 3846

Just remove both node_modules and package-lock.json and run: npm install

or

Just run: npm install -g npm@latest to upgrade it to the latest version

Upvotes: 1

sunknudsen
sunknudsen

Reputation: 7310

Upgrading npm to version 7.5.4 did the job for me.

npm install -g npm@latest

Upvotes: 0

Trolejbus
Trolejbus

Reputation: 115

In my case reinstalling node_modules have not fixed this issue. Problem was with one *.ts file which was missing in source codes. Do not know why It was not displaying compilation error, but adding this missing file to repository solved this issue.

Upvotes: 0

Legends
Legends

Reputation: 22702

Just download and install latest Yarn which is also a node package manager, developed by facebook, but has a much better dependency management. Also update your node cli (optional).

And then, install your dependencies using yarn:

yarn install

or

yarn // short version of yarn install

No errors!

You can continue to use npm after you have installed all dependencies with yarn or continue with yarn....it's your choice.

Upvotes: 4

mpro
mpro

Reputation: 15050

For me ([email protected]) solved the issue by deleting node_modules and performing npm install, but without removing package.json.lock file.

Upvotes: 1

Andy
Andy

Reputation: 7117

I bumped into this issue using nvs (Node Version Switcher - https://github.com/jasongin/nvs) [email protected] and [email protected]. The reason was a local package I had linked with npm link. The solution was to remove that folder.

Upvotes: 0

Sakata Gintoki
Sakata Gintoki

Reputation: 1825

Do 2 steps bellow (Window):

rm -rf ./node_modules to remove node folder

rm package-lock.json to remove package-lock.json file

then npm install to re-install the node modules

Upvotes: 7

Dmitrii Dubrovin
Dmitrii Dubrovin

Reputation: 631

I've made some tests:

[email protected] [email protected] - I have trouble and the test fails

nvm use 8.5.0

[email protected] [email protected] - I have trouble and the test fails

nvm use 8.4.0

[email protected] [email protected] - I have trouble and the test fails

npm install npm@^5 -g

[email protected] [email protected] - I have trouble and the test fails

nvm use 8.6.0
npm install npm@^4 -g

[email protected] [email protected] - no trouble, this fixes it.

Upvotes: 3

KHACHORNCHIT
KHACHORNCHIT

Reputation: 2330

I found same problem when using npm version 5.5.1 to install babel-preset-stage-0

Solution: I downgraded npm to version 5.2.0 and try to install again then it can solve the issue.

npm i -g [email protected]    
npm i -D babel-preset-stage-0

Upvotes: 0

Idan Dagan
Idan Dagan

Reputation: 11635

I had the same problem.

I removed both node_modules and package-lock.json and then did:

npm install 

And it worked.

Edit by @OwlyMoly Due to new updates and the restriction to old dependencies in package-lock.json is causing this conflicts. By doing npm install won't fix this issue. Instead by ditching npm_modules and package-lock.json and doing npm install will load a new node_modules and that supposed to be required by package.json. You have to commit the new package-lock.json along with your latest changes of the project.

Upvotes: 64

Mustafa Celik
Mustafa Celik

Reputation: 2399

npm 5.3.0 is broken for windows 10 after upgrading the nodeJS.
You should downgrade the npm, it is a temporary solution but works fine.

npm install -g [email protected]

Upvotes: 1

glenpike
glenpike

Reputation: 43

Seems to be an issue with a combination of factors.

Some workarounds here:

https://github.com/npm/npm/issues/18238

Upvotes: 1

Hemant
Hemant

Reputation: 170

Try with nvm(Node Version Manager).it help you to install any node version for any project without any Error.

Upvotes: 0

Related Questions