Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Cannot read property '0' of undefined #17858

Closed
3 tasks
OKNoah opened this issue Jul 19, 2017 · 265 comments
Closed
3 tasks

Cannot read property '0' of undefined #17858

OKNoah opened this issue Jul 19, 2017 · 265 comments

Comments

@OKNoah
Copy link

OKNoah commented Jul 19, 2017

I'm opening this issue because:

  • [✓] npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don't understand.
  • Other (see below for feature requests):

What's going wrong?

~/P/dreamer-api *master> npm install --save caminte
npm WARN eslint-config-airbnb@15.0.2 requires a peer of eslint-plugin-jsx-a11y@^5.1.1 but none was installed.
npm WARN eslint-config-airbnb@15.0.2 requires a peer of eslint-plugin-react@^7.1.0 but none was installed.
npm WARN dreamer-api@0.1.0 No repository field.

npm ERR! Cannot read property '0' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/noah/.npm/_logs/2017-07-19T19_09_33_702Z-debug.log

and

~/P/dreamer-api *master> npm remove --save sequelize
npm WARN eslint-config-airbnb@15.0.2 requires a peer of eslint-plugin-jsx-a11y@^5.1.1 but none was installed.
npm WARN eslint-config-airbnb@15.0.2 requires a peer of eslint-plugin-react@^7.1.0 but none was installed.
npm WARN dreamer-api@0.1.0 No repository field.

npm ERR! Cannot read property '0' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/noah/.npm/_logs/2017-07-19T19_11_35_695Z-debug.log

How can the CLI team reproduce the problem?

I do not know.

supporting information:

  • npm -v prints:

5.3.0

  • node -v prints:

v8.1.4

  • npm config get registry prints:

https://registry.npmjs.org/

  • Windows, OS X/macOS, or Linux?:

macOS

  • Network issues:
    • [✓] None
  • Container:
    • [✓] None

EDIT: Seems to only happen with node 8.1.4

@furagi
Copy link

furagi commented Jul 20, 2017

Happens to me too when I try to install chalk. Node version is 6.9.4, npm version is 5.3.0, log:

2468 verbose stack TypeError: Cannot read property '0' of undefined
2468 verbose stack     at rmStuff (/usr/lib64/node_modules/npm/lib/unbuild.js:61:24)
2468 verbose stack     at tryCatcher (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
2468 verbose stack     at ret (eval at makeNodePromisifiedEval (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:13:39)
2468 verbose stack     at lifecycle.then.then (/usr/lib64/node_modules/npm/lib/install/action/unbuild.js:12:12)
2468 verbose stack     at tryCatcher (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
2468 verbose stack     at Promise._settlePromiseFromHandler (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
2468 verbose stack     at Promise._settlePromise (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
2468 verbose stack     at Promise._settlePromise0 (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
2468 verbose stack     at Promise._settlePromises (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/promise.js:693:18)
2468 verbose stack     at Async._drainQueue (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/async.js:133:16)
2468 verbose stack     at Async._drainQueues (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/async.js:143:10)
2468 verbose stack     at Immediate.Async.drainQueues (/usr/lib64/node_modules/npm/node_modules/bluebird/js/release/async.js:17:14)
2468 verbose stack     at runCallback (timers.js:649:20)
2468 verbose stack     at tryOnImmediate (timers.js:622:5)
2468 verbose stack     at processImmediate [as _immediateCallback] (timers.js:594:5)

@jlchereau
Copy link

npm 5.3.0 is broken (on windows 10) for me too after upgrading to nodeJS v8.2.0. Same symptoms/logs as described above. npm install -g npm@5.2.0 temporarily fixes the problem.

@jpbecotte
Copy link

@jlchereau : Thank you!

@gabiap96
Copy link

@jlchereau i had the same error on mint and this worked

@saeedtabrizi
Copy link

Same problem with following configuration .

  • node : 8.2.1
  • npm : 5.3.0

@refack
Copy link

refack commented Jul 23, 2017

Same problem, but I have logs
2017-07-23T16_22_13_400Z-debug.zip
Reproducing repo
citgm-npm-bug.zip

And I think I know what I did "wrong":

  1. git clone https://github.com/nodejs/citgm
  2. npm i
  3. npm i spawn-wrap - wanted to test it - it's not listed in package.json
  4. git pull - that updated package.json
  5. npm i - broken - can't even npm rm spawn-wrap

@refack
Copy link

refack commented Jul 23, 2017

P.S. node@8.1.3 & npm@5.3.0
rimrafing node_modules solves the problem.

@drewpayment
Copy link

Same issue here, but my config:

Node@7.7.4
NPM@5.3.0

Downgrading to NPM@5.2.0 worked perfectly for now.

@jlchereau
Copy link

jlchereau commented Jul 24, 2017

@refack, from my experience rimrafing restores npm install but not npm update as long as any of the modules installed has been shrinkwrapped. In my solution, aws-sdk triggers the error. Restoring npm 5.2.0 is apparently the only way until we get a fix.

@Saturate
Copy link
Contributor

Having the same issue with 5.3.0

4841 verbose stack TypeError: Cannot read property '0' of undefined
4841 verbose stack     at rmStuff (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\lib\unbuild.js:61:24)
4841 verbose stack     at tryCatcher (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
4841 verbose stack     at ret (eval at makeNodePromisifiedEval (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:13:39)
4841 verbose stack     at lifecycle.then.then (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\lib\install\action\unbuild.js:12:12)
4841 verbose stack     at tryCatcher (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
4841 verbose stack     at Promise._settlePromiseFromHandler (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:512:31)
4841 verbose stack     at Promise._settlePromise (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:569:18)
4841 verbose stack     at Promise._settlePromise0 (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:614:10)
4841 verbose stack     at Promise._settlePromises (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:693:18)
4841 verbose stack     at Async._drainQueue (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\async.js:133:16)
4841 verbose stack     at Async._drainQueues (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\async.js:143:10)
4841 verbose stack     at Immediate.Async.drainQueues (C:\Users\teamcity\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
4841 verbose stack     at runCallback (timers.js:672:20)
4841 verbose stack     at tryOnImmediate (timers.js:645:5)
4841 verbose stack     at processImmediate [as _immediateCallback] (timers.js:617:5)
4842 verbose cwd C:\BuildAgent\work\57a4acfd1659de9f\www\Components\FK\Project\Design
4843 verbose Windows_NT 6.3.9600
4844 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\teamcity\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "i"
4845 verbose node v6.10.3
4846 verbose npm  v5.3.0
4847 error Cannot read property '0' of undefined
4848 verbose exit [ 1, true ]

@dennyd
Copy link

dennyd commented Jul 24, 2017

same issue with node 8.1.1, npm 5.3.0

@Wandang
Copy link

Wandang commented Jul 24, 2017

Same issue for me.

Config:
Node@v8.2.1
NPM@5.3.0

@isaaczinda
Copy link

Same issue for me. I'm at npm 5.3.0, node v8.2.1.

@DevYukine
Copy link

same for me npm 5.3.0 node v8.2.1

@weegeekps
Copy link

Same as the others. NPM 5.3.0 and Node v8.2.1

@flubox
Copy link

flubox commented Jul 25, 2017

Same thing here, node@6.9.5 and NPM 5.3.0 won't work, but NPM 5.2.0

@zontafil
Copy link

same,
node 7.9.0, npm 5.3.0

@jorrit
Copy link
Contributor

jorrit commented Jul 25, 2017

I think there are plenty of same here messages already.

@Bejor
Copy link

Bejor commented Jul 25, 2017

Same error for me.
Node 7.9.0, npm 5.3.0

Downgrading to 5.2 solves the issue

@karlvaniseghem
Copy link

same error for me
Node 8.1.2, npm 5.3.0

Downgrading npm to 5.2.0 solves the issue

@CarrierDirectJoe
Copy link

Same error for me
Node 6.11.1, npm 5.3.0

Downgrading npm to 5.2.0 solves the issue

@damienleroux
Copy link

same with v8.1.3 & npm@5.3.0.
Crash on npm i or npm prune.

Same error and same error stack

@elizavetd
Copy link

Same error for me
Node v8.2.1, npm v5.3.0

Downgrading npm to 5.2.0 solves the issue

@Karolis92
Copy link

Same error...
Node v8.2.1, npm v5.3.0

Downgrading npm to 5.2.0 solves the issue

@kenany kenany added the npm5 label Jul 26, 2017
@cullylarson
Copy link

Same error with npm 5.3.0. Downgrading to 5.2.0 fixed it.

@zhaoxiongfei
Copy link

zhaoxiongfei commented Jul 27, 2017

Same error with centos@6.5 & gcc@4.9.2 & node@8.2.1 & npm@5.3.0. Downgrading to 5.2.0 fixed it.

@refack
Copy link

refack commented Jul 27, 2017

@zkat, please say you'll into this... 🙏

@SimonSchick
Copy link

Also present on:

➜  ~ uname -a
Darwin XXXXXXXXXXX 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
➜  ~ node -v
v8.2.1
➜  ~ npm -v
5.3.0

@howlettt
Copy link

Sorry no, the repo is private and already fixed by removing the node_modules folder & reinstalling.
If I see it again I'll try to extract the relevant files to a public repo.

@pb-uk
Copy link

pb-uk commented Nov 30, 2017

I was getting this after an upgrade to npm 5.5.1 but only on some projects - I realised it was those with only devDependencies.

I fixed it by adding an empty dependencies element to my package.json and then npm worked fine, so try this. Strangely though I haven't managed to reproduce the problem by deleting the dependencies element again!

@tsofist
Copy link

tsofist commented Nov 30, 2017

I'm over it
I have solved that issue by installing the Yarn

@arackaf
Copy link

arackaf commented Nov 30, 2017

@zkat there's some repro repo's way at the top of this thread - this one should work too

https://github.com/arackaf/booklist

I downgraded to npm 4 to work around it, but you should be able to use it to test if you're in need of test cases.

@graphicelements
Copy link

graphicelements commented Dec 1, 2017

Same issue here with:
node v8.9.1
npm v5.5.1

Update!!!
This solution worked for me with Gulp:

Run npm rebuild node-sass
Remove node_modules and package-lock.json
Run npm install

@AlexanderKositsyn
Copy link

AlexanderKositsyn commented Dec 5, 2017

Was the same problem.
Solved it by typing:

  1. npm rebuild node-sass
  2. Remove node_modules and package-lock.json
  3. npm init -y
  4. copy-past the old package.json to the new package.json
  5. and then install gulp-pug(pug was a problem that drop down the npm)

@midik
Copy link

midik commented Dec 5, 2017

I confirm that npm@latest does the trick for me:
node 9.2.0
npm 5.6.0

@dennisjac
Copy link

What is the situation here? I ran into the same issue and I'm seeing that the bug is open since July.
Given that npm is a critical part of todays javascript ecosystem it's a bit disconcerting the see this issue getting no attention.

@NN---
Copy link

NN--- commented Dec 7, 2017

@dennisjac Have you tried everything above ? Like removing package-lock.json and installing all packages ?
Did you try 5.6.0 ? It should fix the problem. https://github.com/npm/npm/releases

@zkat
Copy link
Contributor

zkat commented Dec 7, 2017

@dennisjac the situation is that there's been multiple fixes related to this, and most people aren't running into it anymore, but there's a couple of folks still trickling in. Sometimes you have a variety of bugs and they all manifest with the same error. The most notorious is probably cb() not called, which is a reaaaally general one that doesn't tell us much.

@riakharisma
Copy link

Solved for me
win 10
node LTS 8.9.2
npm 5.6.0

@dennisjac
Copy link

The problem is that the first time i fixed things by nuking node_modules, package-lock.json and clearing the cache but now the problem has returned and now I'm thinking about writing a script that nukes everything every time before I do an npm install just to make builds reliable again.

How do I get npm version 5.6.0? I just installed node 8.9.2 but that still has 5.5.1 bundled it seems.

@riakharisma
Copy link

@dennisjac
npm i -g npm@next

@zkat
Copy link
Contributor

zkat commented Dec 8, 2017

Gonna close this, since it seems to be solved for people on 5.6.0

@zkat zkat closed this as completed Dec 8, 2017
@killroy42
Copy link

How do I get onto 5.6.0? I just get this error when I try to upgrade or downgrade in any way:
Error: Cannot find module '/tmp/npm.3077/package/bin/read-package-json.js'

@smithdalec
Copy link

smithdalec commented Dec 11, 2017

Fixed with npm@5.6.0: npm i -g npm@latest
I also had to rm -rf node_modules and npm i from my project once after the npm upgrade. Subsequent installs do not have the error.

@FlandersBurger
Copy link

Downgrading to 5.2.0 and then upgrading to 5.6.0 right after worked for me.

@npm npm locked and limited conversation to collaborators Dec 12, 2017
@zkat
Copy link
Contributor

zkat commented Dec 12, 2017

since this seems to be resolved, I'm gonna lock it -- please open a new issue if you find yourself having this error again (and after making sure you've done the steps of clearing your node_modules/ and installing fresh and all that).

Thanks everyone for participating!

isaacs added a commit to npm/cli that referenced this issue Jun 28, 2019
Fix: npm/npm#17858
Fix: npm/npm#18042
Fix: https://npm.community/t/issue-npm-dedupe-crash-with-typeerror-cannot-read-property-0-of-undefined/644/3
Close: #201

This fixes a bug where a package folder might have a package.json which
is missing or lacks a name property.  It also properly detects the
scoped-ness of a package folder even if the package name is not scoped,
since one might install `express@npm:@scope/express` and end up in that
state.
isaacs added a commit to npm/cli that referenced this issue Jun 28, 2019
Fix: npm/npm#17858
Fix: npm/npm#18042
Fix: https://npm.community/t/issue-npm-dedupe-crash-with-typeerror-cannot-read-property-0-of-undefined/644/3
Close: #201

This fixes a bug where a package folder might have a package.json which
is missing or lacks a name property.  It also properly detects the
scoped-ness of a package folder even if the package name is not scoped,
since one might install `express@npm:@scope/express` and end up in that
state.
isaacs added a commit to npm/cli that referenced this issue Jun 29, 2019
Fix: npm/npm#17858
Fix: npm/npm#18042
Fix: https://npm.community/t/issue-npm-dedupe-crash-with-typeerror-cannot-read-property-0-of-undefined/644/3
Close: #201

This fixes a bug where a package folder might have a package.json which
is missing or lacks a name property.  It also properly detects the
scoped-ness of a package folder even if the package name is not scoped,
since one might install `express@npm:@scope/express` and end up in that
state.
isaacs added a commit to npm/cli that referenced this issue Jun 29, 2019
Fix: npm/npm#17858
Fix: npm/npm#18042
Fix: https://npm.community/t/issue-npm-dedupe-crash-with-typeerror-cannot-read-property-0-of-undefined/644/3
Close: #201

This fixes a bug where a package folder might have a package.json which
is missing or lacks a name property.  It also properly detects the
scoped-ness of a package folder even if the package name is not scoped,
since one might install `express@npm:@scope/express` and end up in that
state.
isaacs added a commit to npm/cli that referenced this issue Jun 29, 2019
Fix: npm/npm#17858
Fix: npm/npm#18042
Fix: https://npm.community/t/issue-npm-dedupe-crash-with-typeerror-cannot-read-property-0-of-undefined/644/3
Close: #201

This fixes a bug where a package folder might have a package.json which
is missing or lacks a name property.  It also properly detects the
scoped-ness of a package folder even if the package name is not scoped,
since one might install `express@npm:@scope/express` and end up in that
state.
isaacs added a commit to npm/cli that referenced this issue Jun 29, 2019
Fix: npm/npm#17858
Fix: npm/npm#18042
Fix: https://npm.community/t/issue-npm-dedupe-crash-with-typeerror-cannot-read-property-0-of-undefined/644/3
Close: #201

This fixes a bug where a package folder might have a package.json which
is missing or lacks a name property.  It also properly detects the
scoped-ness of a package folder even if the package name is not scoped,
since one might install `express@npm:@scope/express` and end up in that
state.
isaacs added a commit to npm/cli that referenced this issue Jun 30, 2019
Fix: npm/npm#17858
Fix: npm/npm#18042
Fix: https://npm.community/t/issue-npm-dedupe-crash-with-typeerror-cannot-read-property-0-of-undefined/644/3
Close: #201

This fixes a bug where a package folder might have a package.json which
is missing or lacks a name property.  It also properly detects the
scoped-ness of a package folder even if the package name is not scoped,
since one might install `express@npm:@scope/express` and end up in that
state.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet