【问题标题】:Cannot run any npm command after Node and npm upgradeNode 和 npm 升级后无法运行任何 npm 命令
【发布时间】:2021-08-02 22:42:09
【问题描述】:

升级到最新的 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 的用户变量

系统变量

运行命令

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

返回

v14.16.1

我使用 Angular 7,ng build 似乎正常工作。

【问题讨论】:

    标签: node.js angular npm


    【解决方案1】:

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

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

    【讨论】:

    • 我从 Apps&Features 卸载并重新安装了 Node,但错误仍然存​​在。此外,无法运行推荐答案的第 1 步(npm cache clean --force)。
    • 您是否尝试删除缓存文件?您是否还尝试更改安装目录?请更新环境变量中的 PATH。
    • 谢谢。我都尝试了,但没有任何改变。我还尝试修复 Nodejs 安装,但没有成功。问题是 node_modules 中的 npm 文件夹。希望我设法通过使用另一个 npm 文件夹来解决它。
    【解决方案2】:

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

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

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

    【讨论】:

    • 你假设 node 最初是使用 nvm 安装的,但事实并非如此。
    猜你喜欢
    • 2019-04-15
    • 1970-01-01
    • 2019-12-22
    • 2017-01-11
    • 2017-09-14
    • 2012-02-14
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    相关资源
    最近更新 更多