Cannot read property 'resolve' of undefined when using npm to install a package

16,394

Solution 1

We do not have much information to work with (as the console output given by Node isn't very useful in this case), but it looks like NPM/Node messed something up while installing.

You stated that you've already tried to re-install Node. You should definitely also re-install NPM (This is a great tutorial to remove both completely: https://stackoverflow.com/a/20711410/10588376).

If you just forgot to mention that you also re-installed NPM and you already did it, I would recommend downgrading Node. You are running v12.4.0 which is the latest (not so stable) version of Node. You could download Node v10.16.0 (https://nodejs.org/en/), which is the LTS (Long Term Support) version of Node (LTS is the recommended version by Node).

As it seems downgrading solved the problem here: https://stackoverflow.com/a/56512076/10588376 (this is for Linux tho, but it could be worth a try on windows too)

Solution 2

Downgrading to node v8.16, then to v10.17 and finally to v12.13 did help for me.

For some reason it helped to install those old versions.

Solution 3

This happened to me due to conflicting NodeJS Versions on my machine. One method to you can try is to completely uninstall NodeJS and NPM using the following instructions https://stackoverflow.com/a/20711410/10588376 . And Reinstall NodeJS after this.

----OR----

You can do what I did (works in cases where NVM is installed) -

  1. Run npm cache clean --force
  2. Go to the control panel --> Programs --> Programs and Features
  3. Scroll down, Uninstall Node.js and check if another file called "nvm for windows 1.1.7" (Version does not matter) if it is present then uninstall that too. Make sure to note down any global npm packages that you have pre-installed as this deletes all instances of global npm packages.
  4. Reboot your machine
  5. Reinstall node.js from https://nodejs.org/en/ by following the installation process It should work now
Share:
16,394

Related videos on Youtube

Scott VanKirk
Author by

Scott VanKirk

Updated on June 04, 2022

Comments