npm error cannot read property 0 of undefined

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

I was trying to do an npm install and kept getting error saying something like “cannot read property 0 of undefined”.

After some googling where I get many instances of “me too” on forums and things like upgrading and downgrading versions of npm sometime works.

But I finally got it to work when I got the clue from the internet to…

  1. delete node_modules folder
  2. delete package-lock.json
  3. do “npm install” to recreate your node_modules folder
  4. then do npm install of whatever module you are trying to install.

Disclaimer: This worked for my case.  It may or may not work for yours.  Do at your own risk, especially when you are deleting your entire node_modules folder.   Make sure that your package.json is good enough that you can restore back your node_modules folder from it.