user9460641
user9460641

Reputation:

Node error Cannot read property 'resolve' of undefined

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 'resolve' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/stash/.npm/_logs/2019-03-11T10_07_30_264Z-debug.log

When I do npm install -verbose:

npm info it worked if it ends with ok
npm verb cli [ '/usr/local/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'install',
npm verb cli   '-verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb npm-session 869376d36eca27b5
npm info lifecycle [email protected]~preinstall: [email protected]
npm timing stage:loadCurrentTree Completed in 22ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 1231ms
npm timing stage:rollbackFailedOptional Completed in 1ms
npm timing stage:runTopLevelLifecycles Completed in 2661ms
npm verb stack TypeError: Cannot read property 'resolve' of undefined
npm verb stack     at regFetch (/usr/local/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js:76:23)
npm verb stack     at fetchPackument (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/packument.js:42:10)
npm verb stack     at packument (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/packument.js:20:10)
npm verb stack     at getManifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:22:10)
npm verb stack     at manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:13:10)
npm verb stack     at Object.manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/index.js:17:12)
npm verb stack     at Object.Fetcher#manifest [as manifest] (/usr/local/lib/node_modules/npm/node_modules/genfun/lib/genfun.js:15:38)
npm verb stack     at manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetch.js:23:18)
npm verb stack     at pinflight (/usr/local/lib/node_modules/npm/node_modules/pacote/manifest.js:24:12)
npm verb stack     at /usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:29:24
npm verb stack     at Promise._execute (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/debuggability.js:313:9)
npm verb stack     at Promise._resolveFromExecutor (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:483:18)
npm verb stack     at new Promise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:79:10)
npm verb stack     at _inflight (/usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:28:25)
npm verb stack     at /usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:22:14
npm verb stack     at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
npm verb cwd /var/www/html/lite-proj/lite-proj
npm verb Linux 4.4.0-142-generic
npm verb argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-verbose"
npm verb node v11.10.1
npm verb npm  v6.7.0
npm ERR! Cannot read property 'resolve' of undefined
npm verb exit [ 1, true ]
npm timing npm Completed in 3862ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/stash/.npm/_logs/2019-03-11T10_12_15_921Z-debug.log

I am not even able to uninstall npm and reinstall it as I am getting the same error when I try to uninstall. What is the issue here and how do I fix it?

Upvotes: 25

Views: 40644

Answers (10)

GHenning
GHenning

Reputation: 11

I encountered the same issue on Windows 10. After uninstalling node and reinstalling a newer version, I got the error "Cannot read property 'resolve' of undefined".

I then uninstalled again, manually deleted the complete installation folder (which was not removed during uninstallation !) and reinstalled the newer node release.

After that, everything worked just fine.

Upvotes: 1

RIshabh
RIshabh

Reputation: 1

There is some issue with the new node version and npm compatibility, install version [https://nodejs.org/dist/v10.15.3/node-v10.15.3-x64.msi] It will work perfectly.

Upvotes: 0

Dave van Eck
Dave van Eck

Reputation: 11

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

Upvotes: 1

Ayush Nanda
Ayush Nanda

Reputation: 91

Instead of version 12.18.3 install version https://nodejs.org/dist/v10.15.3/node-v10.15.3-x64.msi . It will work perfectly.

Upvotes: 0

Munzer
Munzer

Reputation: 2318

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

Upvotes: 2

n0n
n0n

Reputation: 61

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).

Upvotes: 0

Muntasir
Muntasir

Reputation: 808

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.

Upvotes: 7

joseph navin shaji
joseph navin shaji

Reputation: 64

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)

Upvotes: 1

thadk
thadk

Reputation: 1057

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.

Upvotes: 35

user9460641
user9460641

Reputation:

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

Upvotes: 9

Related Questions