3

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 npm@6.9.0
3 info using node@v10.16.0
4 verbose npm-session c94eba96e7c1121e
5 silly install runPreinstallTopLevelLifecycles
6 silly preinstall wordgame@1.0.0
7 info lifecycle wordgame@1.0.0~preinstall: wordgame@1.0.0
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 wordgame@1.0.0
21 silly saveTree +-- @types/express@4.16.1
21 silly saveTree | +-- @types/body-parser@1.17.0
21 silly saveTree | | +-- @types/connect@3.4.32
21 silly saveTree | | | `-- @types/node@10.12.18
21 silly saveTree | | `-- @types/node@10.12.18
21 silly saveTree | +-- @types/express-serve-static-core@4.16.1
21 silly saveTree | | `-- @types/range-parser@1.2.3
21 silly saveTree | `-- @types/serve-static@1.13.2
21 silly saveTree |   `-- @types/mime@2.0.0
21 silly saveTree +-- @types/node@10.12.18
21 silly saveTree +-- @types/seedrandom@2.4.27
21 silly saveTree +-- @types/socket.io@2.1.2
21 silly saveTree +-- @types/ws@6.0.1
21 silly saveTree | `-- @types/events@3.0.0
21 silly saveTree +-- async@2.6.1
21 silly saveTree | `-- lodash@4.17.11
21 silly saveTree +-- bufferutil@4.0.1
21 silly saveTree | `-- node-gyp-build@3.7.0
21 silly saveTree +-- class-transformer@0.2.0
21 silly saveTree +-- express@4.16.4
21 silly saveTree | +-- accepts@1.3.5
21 silly saveTree | | +-- mime-types@2.1.21
21 silly saveTree | | | `-- mime-db@1.37.0
21 silly saveTree | | `-- negotiator@0.6.1
21 silly saveTree | +-- array-flatten@1.1.1
21 silly saveTree | +-- body-parser@1.18.3
21 silly saveTree | | +-- bytes@3.0.0
21 silly saveTree | | +-- content-type@1.0.4
21 silly saveTree | | +-- debug@2.6.9
21 silly saveTree | | | `-- ms@2.0.0
21 silly saveTree | | +-- depd@1.1.2
21 silly saveTree | | +-- http-errors@1.6.3
21 silly saveTree | | | +-- inherits@2.0.3
21 silly saveTree | | | +-- setprototypeof@1.1.0
21 silly saveTree | | | `-- statuses@1.4.0
21 silly saveTree | | +-- iconv-lite@0.4.23
21 silly saveTree | | | `-- safer-buffer@2.1.2
21 silly saveTree | | +-- on-finished@2.3.0
21 silly saveTree | | | `-- ee-first@1.1.1
21 silly saveTree | | +-- qs@6.5.2
21 silly saveTree | | +-- raw-body@2.3.3
21 silly saveTree | | | `-- unpipe@1.0.0
21 silly saveTree | | `-- type-is@1.6.16
21 silly saveTree | |   `-- media-typer@0.3.0
21 silly saveTree | +-- content-disposition@0.5.2
21 silly saveTree | +-- content-type@1.0.4
21 silly saveTree | +-- cookie-signature@1.0.6
21 silly saveTree | +-- cookie@0.3.1
21 silly saveTree | +-- debug@2.6.9
21 silly saveTree | +-- depd@1.1.2
21 silly saveTree | +-- encodeurl@1.0.2
21 silly saveTree | +-- escape-html@1.0.3
21 silly saveTree | +-- etag@1.8.1
21 silly saveTree | +-- finalhandler@1.1.1
21 silly saveTree | | `-- parseurl@1.3.2
21 silly saveTree | +-- fresh@0.5.2
21 silly saveTree | +-- merge-descriptors@1.0.1
21 silly saveTree | +-- methods@1.1.2
21 silly saveTree | +-- on-finished@2.3.0
21 silly saveTree | +-- parseurl@1.3.2
21 silly saveTree | +-- path-to-regexp@0.1.7
21 silly saveTree | +-- proxy-addr@2.0.4
21 silly saveTree | | +-- forwarded@0.1.2
21 silly saveTree | | `-- ipaddr.js@1.8.0
21 silly saveTree | +-- qs@6.5.2
21 silly saveTree | +-- range-parser@1.2.0
21 silly saveTree | +-- safe-buffer@5.1.2
21 silly saveTree | +-- send@0.16.2
21 silly saveTree | | +-- destroy@1.0.4
21 silly saveTree | | `-- mime@1.4.1
21 silly saveTree | +-- serve-static@1.13.2
21 silly saveTree | +-- setprototypeof@1.1.0
21 silly saveTree | +-- statuses@1.4.0
21 silly saveTree | +-- type-is@1.6.16
21 silly saveTree | +-- utils-merge@1.0.1
21 silly saveTree | `-- vary@1.1.2
21 silly saveTree +-- seedrandom@2.4.4
21 silly saveTree +-- socket.io@2.2.0
21 silly saveTree | +-- debug@4.1.1
21 silly saveTree | | `-- ms@2.1.1
21 silly saveTree | +-- engine.io@3.3.2
21 silly saveTree | | +-- base64id@1.0.0
21 silly saveTree | | +-- debug@3.1.0
21 silly saveTree | | +-- engine.io-parser@2.1.3
21 silly saveTree | | | +-- after@0.8.2
21 silly saveTree | | | +-- arraybuffer.slice@0.0.7
21 silly saveTree | | | +-- base64-arraybuffer@0.1.5
21 silly saveTree | | | +-- blob@0.0.5
21 silly saveTree | | | `-- has-binary2@1.0.3
21 silly saveTree | | |   `-- isarray@2.0.1
21 silly saveTree | | `-- ws@6.1.4
21 silly saveTree | |   `-- async-limiter@1.0.0
21 silly saveTree | +-- has-binary2@1.0.3
21 silly saveTree | +-- socket.io-adapter@1.1.1
21 silly saveTree | +-- socket.io-client@2.2.0
21 silly saveTree | | +-- backo2@1.0.2
21 silly saveTree | | +-- component-bind@1.0.0
21 silly saveTree | | +-- component-emitter@1.2.1
21 silly saveTree | | +-- debug@3.1.0
21 silly saveTree | | +-- engine.io-client@3.3.2
21 silly saveTree | | | +-- component-inherit@0.0.3
21 silly saveTree | | | +-- debug@3.1.0
21 silly saveTree | | | +-- has-cors@1.1.0
21 silly saveTree | | | +-- indexof@0.0.1
21 silly saveTree | | | +-- parseqs@0.0.5
21 silly saveTree | | | | `-- better-assert@1.0.2
21 silly saveTree | | | |   `-- callsite@1.0.0
21 silly saveTree | | | +-- parseuri@0.0.5
21 silly saveTree | | | +-- ws@6.1.4
21 silly saveTree | | | +-- xmlhttprequest-ssl@1.5.5
21 silly saveTree | | | `-- yeast@0.1.2
21 silly saveTree | | +-- has-cors@1.1.0
21 silly saveTree | | +-- indexof@0.0.1
21 silly saveTree | | +-- object-component@0.0.3
21 silly saveTree | | +-- parseqs@0.0.5
21 silly saveTree | | +-- parseuri@0.0.5
21 silly saveTree | | +-- socket.io-parser@3.3.0
21 silly saveTree | | | `-- debug@3.1.0
21 silly saveTree | | `-- to-array@0.1.4
21 silly saveTree | `-- socket.io-parser@3.3.0
21 silly saveTree +-- source-map-support@0.5.10
21 silly saveTree | +-- buffer-from@1.1.1
21 silly saveTree | `-- source-map@0.6.1
21 silly saveTree +-- ta-json@2.5.0
21 silly saveTree | `-- reflect-metadata@0.1.12
21 silly saveTree `-- ws@7.0.0
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 ]

halfer
  • 19,824
  • 17
  • 99
  • 186
Scott VanKirk
  • 445
  • 2
  • 5
  • 8
  • A 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 Jun 23 '19 at 23:41
  • Okay, I've followed: https://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. – Scott VanKirk Jun 24 '19 at 00:19
  • Related question: https://stackoverflow.com/q/55099569/823321 – sɐunıɔןɐqɐp Aug 08 '20 at 08:40

6 Answers6

15

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)

MarvinJWendt
  • 2,357
  • 1
  • 10
  • 36
  • 2
    Downgrading 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? – Scott VanKirk Jun 24 '19 at 15:08
  • I 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. – Skystrider Feb 06 '20 at 17:39
  • Now 12.16 is the latest LTS. – Michele Dorigatti Feb 18 '20 at 10:27
1

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.

Sam
  • 28,421
  • 49
  • 167
  • 247
1

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

  1. Run npm cache clean --force
  2. Go to the control panel --> Programs --> Programs and Features
  3. 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.
  4. Reboot your machine
  5. Reinstall node.js from https://nodejs.org/en/ by following the installation process It should work now
0

this helped me:

install back old: node-v10.15.3-x64.msi

then over it install: node-v12.18.0-x64.msi

now works fine without 'resolve' of undefined

jmp
  • 2,456
  • 3
  • 30
  • 47
0

This helped me (Windows 10 x64):

  • Uninstall last version or x64 version of node.js

  • Install a different version or x86 version of node.js

  • Try to install npm again.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
0

The generic answer is:-

You need to uninstall the:-

  1. nodejs.
  2. user/appdata/romaing/npm-cache (delete this)
  3. user/appdata/romaing/node (delete this)
  4. uninstall Node Version Manager (nvm) (As it will interrupt with your older version of node and their global variable.)

Then again install node. Everything will work fine.

Happy coding!

aashray jain
  • 301
  • 3
  • 3