Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node error Cannot read property 'resolve' of undefined

Tags:

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?

like image 777
zinngg Avatar asked Mar 11 '19 10:03

zinngg


1 Answers

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.

like image 167
thadk Avatar answered Sep 23 '22 15:09

thadk