使用npm安装软件包时,无法读取未定义的属性“ resolve”

时间:2019-06-23 01:59:17

标签: node.js windows npm

我无法使用npm在Windows 10计算机上执行任何操作。我总是得到:npm ERR!无法读取未定义的属性“ resolve”。

如果重要的话,我正在使用VSCode。

npm安装npm -g

给我和“ npm i”相同的信息。我已经卸载了Node并重新安装了两次,但这没有帮助。我删除了唯一的开发目录中的node-modules目录。我没有其他想法。请帮助

这是现在完整的日志的样子:

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 ]

7 个答案:

答案 0 :(得分:2)

我们没有太多信息可以使用(因为在这种情况下,Node提供的控制台输出不是很有用),但是看起来NPM / Node在安装时弄乱了某些东西。

您表示已经尝试重新安装 Node 。您当然也应该重新安装 NPM (这是一个很好的教程,可以完全删除两者:https://stackoverflow.com/a/20711410/10588376)。

如果您只是忘记提及您还重新安装了 NPM 而您已经做到了,那么我建议您降级Node。您正在运行v12.4.0,这是Node的最新版本(不稳定)。您可以下载Node v10.16.0(https://nodejs.org/en/),它是Node的LTS(长期支持)版本(LTS是Node推荐的版本)。

降级似乎可以解决以下问题:https://stackoverflow.com/a/56512076/10588376(这是针对Linux的,但是在Windows上也值得尝试)

答案 1 :(得分:1)

这发生在我身上是因为我机器上的 NodeJS 版本冲突。 您可以尝试的一种方法是使用以下说明 https://stackoverflow.com/a/20711410/10588376 完全卸载 NodeJS 和 NPM。 并在此之后重新安装 NodeJS。

----或----

你可以做我所做的(在安装了 NVM 的情况下有效)-

  1. 运行 npm cache clean --force
  2. 转到控制面板 --> 程序 --> 程序和功能
  3. 向下滚动,卸载 Node.js 并检查是否存在另一个名为“nvm for windows 1.1.7”(版本无关紧要)的文件,然后也将其卸载。 请务必记下您预安装的所有全局 npm 包,因为这会删除全局 npm 包的所有实例。
  4. 重启你的机器
  5. 按照安装过程从 https://nodejs.org/en/ 重新安装 node.js 现在应该可以使用了

答案 2 :(得分:0)

降级到节点v8.16,然后降级到v10.17,最后降级到v12.13确实对我有帮助。

由于某种原因,它有助于安装那些旧版本。

答案 3 :(得分:0)

我遇到了同样的问题,安装了Node js的10.15.3版本并完成了。

答案 4 :(得分:0)

这对我有帮助:

重新安装旧版:node-v10.15.3-x64.msi

然后在其上安装:node-v12.18.0-x64.msi

现在可以正常工作,而无需“解决”未定义的

答案 5 :(得分:0)

这对我有帮助(Windows 10 x64):

  • 卸载最新版本或x64版本的node.js

  • 安装不同版本或x86版本的node.js

  • 尝试再次安装npm。

答案 6 :(得分:0)

一般答案是:-

您需要卸载:-

  1. nodejs。
  2. user/appdata/romaing/npm-cache(删除这个)
  3. user/appdata/romaing/node(删除这个)
  4. 卸载节点版本管理器 (nvm)(因为它会因旧版本的节点及其全局变量而中断。)

然后再次安装节点。一切都会好起来的。

快乐编码!