Node 和 npm 升级后无法运行任何 npm 命令

时间:2021-04-07 08:23:47

标签: node.js angular npm

升级到最新的 Node 和 npm 版本后,当我尝试任何 npm 命令时,出现以下错误:

 C:\Users\Giannis\source\repos\cfFrame\CloudFinApp>npm doctor
    TypeError: Cannot read property 'prefix' of undefined
        at parseField (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\parse-field.js:15:43)
        at Config.parseField (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:438:12)
        at Config.[loadObject] (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:430:24)
        at Config.loadDefaults (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:268:22)
        at Config.load (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:207:10)
        at Object.[_load] (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\lib\npm.js:176:23)
    Error: call config.load() before reading values
        at Config.get (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:163:13)
        at errorHandler (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\lib\utils\error-handler.js:179:32)
        at Object.<anonymous> (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\lib\cli.js:42:14)
        at Object.onceWrapper (events.js:422:26)
        at Object.emit (events.js:315:20)
        at C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\lib\npm.js:148:12
    Error: call config.load() before reading values
        at Config.get (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:163:13)
        at process.errorHandler (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\lib\utils\error-handler.js:179:32)
        at process.emit (events.js:315:20)
        at processPromiseRejections (internal/process/promises.js:245:33)
        at processTicksAndRejections (internal/process/task_queues.js:94:32)
    C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:163
          throw new Error('call config.load() before reading values')
          ^
    
    Error: call config.load() before reading values
        at Config.get (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\config\lib\index.js:163:13)
        at process.errorHandler (C:\Users\Giannis\AppData\Roaming\npm\node_modules\npm\lib\utils\error-handler.js:179:32)
        at process.emit (events.js:315:20)
        at process._fatalException (internal/process/execution.js:163:25)

运行命令 npm -vnpm outdated 返回相同的错误。

我以管理员身份运行 cmd。

环境变量

Giannis 的用户变量

enter image description here

系统变量

enter image description here

运行命令

C:\Users\Giannis\source\repos\cfFrame\CloudFinApp>node --version

返回

v14.16.1

我使用 Angular 7 并且 ng build 似乎像往常一样工作。

2 个答案:

答案 0 :(得分:0)

有一次我遇到了同样的问题。无论是任何命令,Node 都会抛出错误。经过一番研究,我找到了解决方案,即从我的系统中完全卸载和删除 Node,然后重新安装一个新版本。

考虑这个答案以从系统中完全删除 Node: How to completely remove node.js from Windows

答案 1 :(得分:-1)

其实不用重新安装,用nvm改变node版本即可。

某些节点版本与 npm 版本不兼容。 ,

所以首先,检查您的节点版本,然后使用节点版本管理器(nvm)更改您当前的节点版本以与您的 npm 版本兼容。