Cannot read property 'resolve' of undefined when using npm to install a package
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) -
- Run npm cache clean --force
- Go to the control panel --> Programs --> Programs and Features
- 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.
- Reboot your machine
- Reinstall node.js from https://nodejs.org/en/ by following the installation process It should work now
Related videos on Youtube
Scott VanKirk
Updated on June 04, 2022Comments
-
Scott VanKirk almost 2 years
I cannot use npm to do anything on my Windows 10 machine. I always get: npm ERR! Cannot read property 'resolve' of undefined.
I am using VSCode.
npm install npm -g
gives me the same message as does "npm i". I have uninstalled Node and reinstalled it twice and it doesn't help. I removed the node-modules directory in my only development directory. I have no other ideas.
This is what the now complete log looks like:
0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe', 1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 1 verbose cli 'i' ] 2 info using [email protected] 3 info using [email protected] 4 verbose npm-session c94eba96e7c1121e 5 silly install runPreinstallTopLevelLifecycles 6 silly preinstall [email protected] 7 info lifecycle [email protected]~preinstall: [email protected] 8 silly install loadCurrentTree 9 silly install readLocalPackageData 10 timing stage:loadCurrentTree Completed in 13ms 11 silly install loadIdealTree 12 silly install cloneCurrentTreeToIdealTree 13 timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms 14 silly install loadShrinkwrap 15 timing stage:loadIdealTree:loadShrinkwrap Completed in 76ms 16 silly install loadAllDepsIntoIdealTree 17 silly fetchPackageMetaData error for typescript@^3.5.1 Cannot read property 'resolve' of undefined 18 silly fetchPackageMetaData error for typescript@^3.5.1 Cannot read property 'resolve' of undefined 19 timing stage:rollbackFailedOptional Completed in 0ms 20 timing stage:runTopLevelLifecycles Completed in 223ms 21 silly saveTree [email protected] 21 silly saveTree +-- @types/[email protected] 21 silly saveTree | +-- @types/[email protected] 21 silly saveTree | | +-- @types/[email protected] 21 silly saveTree | | | `-- @types/[email protected] 21 silly saveTree | | `-- @types/[email protected] 21 silly saveTree | +-- @types/[email protected] 21 silly saveTree | | `-- @types/[email protected] 21 silly saveTree | `-- @types/[email protected] 21 silly saveTree | `-- @types/[email protected] 21 silly saveTree +-- @types/[email protected] 21 silly saveTree +-- @types/[email protected] 21 silly saveTree +-- @types/[email protected] 21 silly saveTree +-- @types/[email protected] 21 silly saveTree | `-- @types/[email protected] 21 silly saveTree +-- [email protected] 21 silly saveTree | `-- [email protected] 21 silly saveTree +-- [email protected] 21 silly saveTree | `-- [email protected] 21 silly saveTree +-- [email protected] 21 silly saveTree +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | `-- [email protected] 21 silly saveTree +-- [email protected] 21 silly saveTree +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | | `-- [email protected] 21 silly saveTree | | | | `-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | +-- [email protected] 21 silly saveTree | | | `-- [email protected] 21 silly saveTree | | `-- [email protected] 21 silly saveTree | `-- [email protected] 21 silly saveTree +-- [email protected] 21 silly saveTree | +-- [email protected] 21 silly saveTree | `-- [email protected] 21 silly saveTree +-- [email protected] 21 silly saveTree | `-- [email protected] 21 silly saveTree `-- [email protected] 22 verbose stack TypeError: Cannot read property 'resolve' of undefined 22 verbose stack at regFetch (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-fetch\index.js:76:23) 22 verbose stack at fetchPackument (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\packument.js:42:10) 22 verbose stack at packument (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\packument.js:20:10) 22 verbose stack at getManifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\manifest.js:22:10) 22 verbose stack at manifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\manifest.js:13:10) 22 verbose stack at Object.manifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\index.js:17:12) 22 verbose stack at Object.Fetcher#manifest [as manifest] (C:\Program Files\nodejs\node_modules\npm\node_modules\genfun\lib\genfun.js:15:38) 22 verbose stack at manifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetch.js:23:18) 22 verbose stack at pinflight (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\manifest.js:24:12) 22 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\promise-inflight\inflight.js:29:24 22 verbose stack at Promise._execute (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\debuggability.js:313:9) 22 verbose stack at Promise._resolveFromExecutor (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:483:18) 22 verbose stack at new Promise (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:79:10) 22 verbose stack at _inflight (C:\Program Files\nodejs\node_modules\npm\node_modules\promise-inflight\inflight.js:28:25) 22 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\promise-inflight\inflight.js:22:14 22 verbose stack at tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23) 23 verbose cwd F:\dev\javascript\words 24 verbose Windows_NT 10.0.17134 25 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i" 26 verbose node v10.16.0 27 verbose npm v6.9.0 28 error Cannot read property 'resolve' of undefined 29 verbose exit [ 1, true ]
-
Scott VanKirk almost 5 yearsA bit more info: This happens with both node 10.16 and 12.4. According to the node documentation, the node installation installs both node and npm and uninstalling node uninstalls npm as well. "npm cache clean --force" doesn't change anything
-
Scott VanKirk almost 5 yearsOkay, I've followed: stackoverflow.com/a/20711410/10588376) as Marvin has suggested. I've scrubbed any mention of NPM off my machine, rebooted, reinstalled Node 10.16 and STILL I get the same error any time I try to run NPM.
-
sɐunıɔןɐqɐp almost 4 yearsRelated question: stackoverflow.com/q/55099569/823321
-
-
Scott VanKirk almost 5 yearsDowngrading worked! After uninstalling everything once again, I installed V8.16. npm worked. Then I installed V10.16 and V12.4 and both times npm worked again! WTF? I've never even had V8.16 on this computer and everything was working until just recently. I've been wracking my brains trying to remember any changes I made to this machine, but I got nothing. Any thoughts on this?
-
Skystrider over 4 yearsI didn't need to downgrade. Uninstall of node and npm and then reinstall fresh worked for me. First link in MarginJWendt's answer for how to completely remove node/npm worked for me.
-
Michele Dorigatti about 4 yearsNow 12.16 is the latest LTS.