Node error Cannot read property 'resolve' of undefined Node error Cannot read property 'resolve' of undefined reactjs reactjs

Node error Cannot read property 'resolve' of undefined


I got into this situation with an old version of the n node version switcher (~v2), having switched onto Node v12. I was able to fix it by switching to a much older version of Node it had installed using n, v8 worked for me, and then upgrade the version switcher with sudo npm install -g n.

From there I could switch to any version of node and use npm again.


The reason for the error was probably conflicting global packages and node versions. I uninstalled node and npm and then reinstalled them.

To remove nodejs and associated packages (like npm):

sudo apt-get purge --auto-remove nodejs

Nodejs and npm will leave files in the system which may cause issues during reinstallation. I had to remove them as well.

Although it is a bad practice to remove packages manually (it may cause problems with the package manager), it helped my case. This answer shows how to remove nodejs and related files manually.

To reinstall them:

sudo apt-get updatesudo apt-get install nodejssudo apt-get install npm


So I have recently faced a very similar problem when I was trying to run a react project in my Windows 10 x64 PC. Although I installed Node.js v12.13.0 (+ npm v6.12.0) x64; I couldn't execute npm install command, as it would give me this same error (Cannot read property 'resolve' of undefined).

Then according to this comment, I uninstalled the x64 version of Node.js and then installed the x86 version. After this, I could execute the npm install command successfully.