This repository has been archived by the owner. It is now read-only.

npm5 Error: "Cannot read property 'find' of undefined" #16677

Open
corbinu opened this Issue May 21, 2017 · 54 comments

Comments

Projects
None yet
@corbinu
Copy link

corbinu commented May 21, 2017

I'm opening this issue because:

npm is producing an incorrect install.

What's going wrong?

Sometimes on OS X and Linux Node 7.10.0 I am getting Cannot read property 'find' of undefined

How can the CLI team reproduce the problem?

It seems to be on some installs randomly

supporting information:

  • npm -v prints: 5.0.0-beta.57
  • node -v prints: v7.10.0
  • npm config get registry prints: https://registry.npmjs.org/
  • Windows, OS X/macOS, or Linux?: macOS sierra and Ubuntu 17.04
  • Network issues:
    • Geographic location where npm was run: SoCal no VPN or Proxy
  • Container: No Container

Log Gist

@corbinu corbinu changed the title npm5 Cannot read property 'find' of undefined npm5 Error: "Cannot read property 'find' of undefined" May 21, 2017

@JacopKane

This comment has been minimized.

Copy link

JacopKane commented May 22, 2017

Having the same error. You can find the error stack trace if it will be helpful:

963 verbose stack TypeError: Cannot read property 'find' of undefined
5963 verbose stack     at opts.integrity.digests.find.hash (/usr/local/lib/node_modules/npm5/node_modules/ssri/index.js:257:33)
5963 verbose stack     at Array.find (native)
5963 verbose stack     at Transform.on (/usr/local/lib/node_modules/npm5/node_modules/ssri/index.js:256:15)
5963 verbose stack     at emitNone (events.js:91:20)
5963 verbose stack     at Transform.emit (events.js:188:7)
5963 verbose stack     at endReadableNT (_stream_readable.js:974:12)
5963 verbose stack     at _combinedTickCallback (internal/process/next_tick.js:80:11)
5963 verbose stack     at process._tickCallback (internal/process/next_tick.js:104:9)
@corbinu

This comment has been minimized.

Copy link

corbinu commented May 23, 2017

Just wanted to report this still happens in beta.58

@zkat zkat added the npm5 label May 24, 2017

@corbinu

This comment has been minimized.

Copy link

corbinu commented May 24, 2017

Think I figured it out... looks like it is actually a cache bug from using much earlier versions of npm5. Blowing away the .npm dir fixed it :)

@zkat

This comment has been minimized.

Copy link
Member

zkat commented May 25, 2017

@JacopKane @corbinu can either of you still repro this? I just pushed beta.62 which should at least make the error more local and obvious.

@corbinu

This comment has been minimized.

Copy link

corbinu commented May 25, 2017

@zkat I haven't been able to repo since I blew away my .npm folder even on 59 so sorry not sure how to get the better error message to show you. I am pretty sure it was actually a product of much earlier versions of the beta putting something incorrect in the cache though. Sorry :/

@zkat

This comment has been minimized.

Copy link
Member

zkat commented May 25, 2017

@corbinu yeah, not surprised if that's the case. Don't worry about it. It's pretty likely this has to do with, say, git dependencies 'cause I need to get rid of the integrity hash for those, since it will change between installs (packing tarballs isn't currently "stable" from a hash perspective, and it'll keep being this way until we start packing them with tarv3's opts.portable option)

@zkat

This comment has been minimized.

Copy link
Member

zkat commented May 25, 2017

Since the OP can't repro this and any errors coming from this are gonna be very different now, I'm gonna go ahead and close this and wait to see if anyone else is running into the underlying issue. Cheers!

@zkat zkat closed this May 25, 2017

@corbinu

This comment has been minimized.

Copy link

corbinu commented May 25, 2017

Ok sounds good. That makes sense... what might have happened then is I did actually do a new release of my personal eslint rules module where I switched from having a few dependencies installing via git to having them be the npm package. Let me test and see if that replicates it.

@olalonde

This comment has been minimized.

Copy link

olalonde commented May 31, 2017

Also had this error in node v8.0.0 and npm@5.0.0

@corbinu

This comment has been minimized.

Copy link

corbinu commented May 31, 2017

@olalonde did you try deleting your .npm folder as I did?

@olalonde

This comment has been minimized.

Copy link

olalonde commented May 31, 2017

Yes, that fixed it

@tjiang11

This comment has been minimized.

Copy link

tjiang11 commented Jun 1, 2017

You can also run npm cache verify. That fixed it for me.

@dstockhofe

This comment has been minimized.

Copy link

dstockhofe commented Jun 1, 2017

Fixed it for me too, thanks

@zkat

This comment has been minimized.

Copy link
Member

zkat commented Jun 1, 2017

This specific error can't happen in the latest versions of npm5. I suspect there's a deeper problem going on here, but I don't know if it'll rear its head again. If you have a similar issue to this, please reply here with a full debug log so I can take another look -- but I have no idea how the current code could possibly give this exact error after my fix.

If anyone else is experiencing this: please update to the latest npm with npm i -g npm@latest. The npm5 beta version is no longer supported.

@NN---

This comment has been minimized.

Copy link

NN--- commented Jun 1, 2017

Got same error using latest node with npm from http://nodejs.org/
After deleting %appdata%\npm-cache , the issue disappeared.

@strongui

This comment has been minimized.

Copy link

strongui commented Jun 1, 2017

Having install issues, even after deleting the cache folder: I'm on 5.0.1
2017-06-01T14_59_14_289Z-debug.txt

@zkat

This comment has been minimized.

Copy link
Member

zkat commented Jun 1, 2017

@strongui this is a separate issue, with node-sass. Please search the issue tracker for node-sass errors with npm5

@ELLIOTTCABLE

This comment has been minimized.

Copy link

ELLIOTTCABLE commented Jun 3, 2017

I'm seeing this on Node v8.0.0 w/ npm 5.0.1.

Reproducible for me with my current setup, in a brand-new directory, with this config, producing this log. I'm afraid to blow away .npm or run npm cache verify, since it sounds like you're having trouble reproducing this error, whereas it's currently happening consistently for me.

Excerpt:

4563 verbose stack TypeError: Cannot read property 'find' of undefined
4563 verbose stack     at opts.integrity.digests.find.hash (/Users/ec/.nvm/versions/node/v8.0.0/lib/node_modules/npm/node_modules/ssri/index.js:264:33)
4563 verbose stack     at Array.find (native)
4563 verbose stack     at Transform.on (/Users/ec/.nvm/versions/node/v8.0.0/lib/node_modules/npm/node_modules/ssri/index.js:263:15)
4563 verbose stack     at emitNone (events.js:110:20)
4563 verbose stack     at Transform.emit (events.js:207:7)
4563 verbose stack     at endReadableNT (_stream_readable.js:1045:12)
4563 verbose stack     at _combinedTickCallback (internal/process/next_tick.js:102:11)
4563 verbose stack     at process._tickCallback (internal/process/next_tick.js:161:9)

Let me know if you need any further debugging information from my setup, or if it's useless to you and I can go ahead and try cache verify etc. <3

@gr2m

This comment has been minimized.

Copy link

gr2m commented Jun 3, 2017

@zkat just wanted to let you know that I run into the same problem with npm@5.0.2. Deleting ~/.npm fixed it for me, too.

Simplest case to reproduce it for me was with the glob package: isaacs/node-glob#341

@olalonde

This comment has been minimized.

Copy link

olalonde commented Jun 5, 2017

@zkat no idea really but #16807 might be related?

@vcostin

This comment has been minimized.

Copy link

vcostin commented Jun 5, 2017

@tjiang11 solution worked for me node v7.10.0 and npm 5.0.2

@zkat

This comment has been minimized.

Copy link
Member

zkat commented Jun 5, 2017

Something fishy's going on here. Reopening and investigating further.

@zkat zkat reopened this Jun 5, 2017

@hinell

This comment has been minimized.

Copy link

hinell commented Jun 5, 2017

Getting this error too. 😟

Platform: Microsoft Windows 10 Pro x64

$ npm -v && node -v
5.0.2
v8.0.0
TypeError: Cannot read property 'find' of undefined
    at opts.integrity.digests.find.hash (C:\Users\Alex\AppData\Roaming\npm\node_modules\npm\node_modules\ssri\index.js:264:33)
    at Array.find (native)
    at Transform.on (C:\Users\Alex\AppData\Roaming\npm\node_modules\npm\node_modules\ssri\index.js:263:15)
    at emitNone (events.js:110:20)
    at Transform.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1045:12)
    at _combinedTickCallback (internal/process/next_tick.js:102:11)
    at process._tickCallback (internal/process/next_tick.js:161:9)

The error is gone away after running the npm cache verify command as suggested above.
Seems like something bad happened to the ssri's cache after installing latest npm version.

By the way: I got this error when typed npm install -g npm-check-updates and npm docs ssri commands respectively. I hope this helps.

@frdmn

This comment has been minimized.

Copy link

frdmn commented Jun 6, 2017

Ran into the same issues using npm 5.0.1 and node 8.0.0 on macOS. Deleting the ~/.npm directory did the trick :)

rm -rf ~/.npm 
@mblua

This comment has been minimized.

Copy link

mblua commented Jun 6, 2017

When i have a problem with npm... i just try with yarn and it simply works perfectly. =/

@corbinu

This comment has been minimized.

Copy link

corbinu commented Jun 6, 2017

@mblua if your having this issue please try the fix I posted or the newest version (5.0.3) and let us know if neither works. Just saying "yarn works" doesn't help anybody. I have run into plenty of issues with yarn but my giving feedback there of "it works in npm" wouldn't have helped anybody.

@zkat

This comment has been minimized.

Copy link
Member

zkat commented Jun 6, 2017

@mblua this is already fixed in 5.0.3. Please go ahead and update.

@iameli

This comment has been minimized.

Copy link

iameli commented Jun 7, 2017

@zkat Confirmed fixed in my case -- would you like us to do anything with the newly resulting EINTEGRITY warnings? This doesn't seem to be breaking anything but let me know if there's anything I can do to help track down root cause.

> npm install --save docker-file-parser
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha1-wZyd+aAocC1nhhI4SmVSQExjbRU= integrity checksum failed when using sha1: wanted sha1-wZyd+aAocC1nhhI4SmVSQExjbRU= but got sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==. (15621 bytes)
@zkat

This comment has been minimized.

Copy link
Member

zkat commented Jun 7, 2017

@iameli Oh this is interesting. I wonder how that hash got in there. Does the warning happen every time now? It looks like the caching code for make-fetch-happen is getting mixed up about which algorithm to use somehow.

@zkat

This comment has been minimized.

Copy link
Member

zkat commented Jun 7, 2017

@iameli if you're getting this, please don't delete your cache (move it if you need to?) I have an idea of what might be causing this 👍

@iameli

This comment has been minimized.

Copy link

iameli commented Jun 7, 2017

@zkat Pretty inconsistent repro, unfortunately, but here's my cache anyway in case it's useful: https://s3.amazonaws.com/pub.iame.li/iameli-dotnpm.tar.gz

I'll try and archive it right away if I see that error again.

Only weird thing I'm doing in the repo is using Lerna, so maybe something weird happening with symlinked package-lock.json files or something?

@mblua

This comment has been minimized.

Copy link

mblua commented Jun 7, 2017

@corbinu I understand your point. But my comment was not trying to hurt anyone, i was just saying that i'm tired of this situation. Was an emotional post, sorry. Perhaps becouse i always use npm, i really never had a yarn issue.

@zkat Thanks. It has worked great.

@zkat

This comment has been minimized.

Copy link
Member

zkat commented Jun 7, 2017

@iameli I changed the way these warnings are handled and fixed one place where I wasn't doing what I thought I was doing. Would you be so kind as to try and see if you can still repro with npmc@5.0.3-canary.10? <3

@coreh

This comment has been minimized.

Copy link

coreh commented Jun 13, 2017

I was originally hitting:

> node-sass@4.5.3 postinstall /Users/coreh/Projects/redacted/node_modules/node-sass
> node scripts/build.js

module.js:487
    throw err;
    ^

Error: Cannot find module 'lru-cache'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/coreh/Projects/redacted/node_modules/node-sass/node_modules/cross-spawn/lib/parse.js:4:11)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)

Figured it could be related to the package-lock.json file, so I deleted it and hit the error described by this issue:

npm ERR! Cannot read property 'find' of undefined
npm ERR! Cannot read property 'find' of undefined

Deleting the ~/.npm directory as suggested by @corbinu worked.

I'm on npm v5.0.3

@andregoncalvesdev

This comment has been minimized.

Copy link

andregoncalvesdev commented Jun 14, 2017

i had the same issue. I was on npm version 5.0.1. Updated to 5.0.3 fixed for me.

@kildareflare

This comment has been minimized.

Copy link

kildareflare commented Jun 15, 2017

npm 5.01
node 6.9.1
windows 10

Had the same issue Cannot read property 'find' of undefined.
I was unable to use the windows npm upgrader, since I could not install it - catch22!
But what did work was:
Upgrade node to 6.11.0 and npm cache verify

@robgev

This comment has been minimized.

Copy link

robgev commented Jun 20, 2017

Had the same issue today.
Versions:
npm - 5.0.2
node - 8.0.0
ubuntu 16.04

@tjiang11 solution worked well.
I think updating npm and node will work as well.

@gtzinos

This comment has been minimized.

Copy link

gtzinos commented Jun 30, 2017

Hello guys,

I had the same issue, i deleted:

  1. node_modules folder
  2. package.lock.json (i am not sure if it is a good idea)
  3. npm cache verify
@diego-abarca

This comment has been minimized.

Copy link

diego-abarca commented Jul 3, 2017

node: v6.10.2
npm: 5.0.2

updating to npm 5.0.4 fixed the issue for me

@paragw09ckp

This comment has been minimized.

Copy link

paragw09ckp commented Jul 27, 2017

Getting the same issue. Where is the npm folder located on Windows 7?

None of the things worked so wanted to delete npm folder and try again.

npm: 5.0.1
node: 6.11.1
OS; Windows 7

@paragw09ckp

This comment has been minimized.

Copy link

paragw09ckp commented Jul 27, 2017

I found it. the npm folder on Windows 7 is apparently in "C:\Users\myUser\AppData\Roaming".

Along with 'npm' there is a 'npm-cache' folder as well. Should I delete just 'npm' or both? And more importantly, how do I get them back? Is it by installing Node and npm again?

@xavis

This comment has been minimized.

Copy link

xavis commented Aug 11, 2017

I had this problem, but after running

npm cache clean --force

everything works right again 😄

@katwal-dipak

This comment has been minimized.

Copy link

katwal-dipak commented Aug 17, 2017

npm cache verify , it solved the issue in my case.

@jony89

This comment has been minimized.

Copy link

jony89 commented Aug 19, 2017

cleaning cache didn't work for me. this need to be solved.

@ctolkien

This comment has been minimized.

Copy link

ctolkien commented Sep 7, 2017

Hitting this as well.

Blowing away the local node_modules the lock file and npm cache verify to resolve it.

on npm 5.0.0

@ctsstc

This comment has been minimized.

Copy link

ctsstc commented Oct 5, 2017

Just updated npm from 5.3.0 --> 5.4.2 and got this error when trying to install a new package globally.
Ran npm cache verify as mentioned above and it works now.

@NN---

This comment has been minimized.

Copy link

NN--- commented Oct 5, 2017

So far with NPM 5.5.1 and Node 8.6.0 I didn't see this problem happening anymore.

@yug95

This comment has been minimized.

Copy link

yug95 commented Jan 9, 2018

npm verify cache worked for me

@KirillFE

This comment has been minimized.

Copy link

KirillFE commented Jan 24, 2018

npm verify cache works!

@Prasoon1983

This comment has been minimized.

Copy link

Prasoon1983 commented Jun 13, 2018

i got same issue with latest npm(8.11.2) + latest cordova (8.0.0). I tried every solution suggested above but none worked. I had to uninstall Node and completely remove node files from my machine and then reinstall everything to get this working.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.