I am using reactjs and am unable to install any packages using npm install
. The error message I\'m getting is :
npm ERR! Cannot read property \'reso
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 update
sudo apt-get install nodejs
sudo apt-get install npm
The problem may occur if you are using node version manager(nvm) try uninstalling it , i had the same issue and i uninstalled nvm and tried it .
Worked with all versions of node . (worked fine with node 10.15.3,10.16 and 12.7)
I installed Node sometime ago (approximately 1 year ago) and npm worked properly. The node version was 10.15.3. After the install and having written a few small apps - I did not work with Node again until today. Trying to install express with npm - I got the error of: "npm ERR! Cannot read property 'resolve' of undefined" even though it had worked previously. Noting that the Node version was old, I uninstalled and installed the latest version. In my case, I installed into the c:\NodeJs folder (where it was installed previously). This made no difference - I got the same error. I then uninstalled and re-installed into the default folder of c:\Program Files\nodejs and npm works again. Hopefully this might help someone else
The same issue occurred for me on FreeBSD after I tried to update a really outdated node installation.
After removing node and npm packages (pkg delete node8-8.16.2
) I had to manually remove /usr/local/lib/node_modules
directory (some npm dependencies had been left behind and that caused the problem).
Anyone having this issue and have scrolled this far, if you are installing node manually and you have nvm
installed then this might be the issue, don't do it manually, and don't uninstall nvm to fix the issue, just let nvm install the version for you rather than doing it manually, if you don't have nvm installed and you are lost trying upgrading/downgrading node/npm versions, then install nvm
and let it handle all these things for you.
Use nvm install x.x.x
, then nvm use x.x.x
, and everything worked just fine.
more about nvm
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.