【问题标题】:Cannot update version of node - unexpected token无法更新节点版本 - 意外标记
【发布时间】:2023-01-27 00:40:50
【问题描述】:

最近为了技术评估将我的节点降级到第 12 版,现在想升级但似乎出了点问题。我尝试了很多每个人都建议的事情。

不是一个非常熟练的 mac 用户,所以任何帮助表示赞赏

MacBook-Pro ~ % npm install -g n
ERROR: npm v9.1.2 is known not to run on Node.js v12.22.12. You'll need to
upgrade to a newer Node.js version in order to use this version of npm. This
version of npm supports the following node versions: `^14.17.0 || ^16.13.0 ||
>=18.0.0`. You can find the latest version at https://nodejs.org/.

ERROR:
/usr/local/lib/node_modules/npm/lib/utils/exit-handler.js:22
  const hasLoadedNpm = npm?.config.loaded
                           ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at module.exports (/usr/local/lib/node_modules/npm/lib/cli.js:76:23)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:25)
    at Module._compile (internal/modules/cjs/loader.js:999:30)

-MacBook-Pro ~ % node -v
v12.22.12

试过 npm install -g n

【问题讨论】:

    标签: macos npm node-modules


    【解决方案1】:

    尝试使用 nodejs.org/ 上的 OSX 安装程序。它将更新您的本地节点安装以及兼容的 npm 版本(撰写本文时为 v8.19.2)。然后输入node -v时错误应该消失了。

    【讨论】:

      【解决方案2】:

      错误: /usr/local/lib/node_modules/npm/lib/utils/exit-handler.js:22 const hasLoadedNpm = npm?.config.loaded ^ SyntaxError: 意外的标记 '.'

      要解决这些问题,您必须从系统中删除节点和 npm,然后重新安装它们。那么你可以解决这个问题。

      1. 首先安装 Homebrew

        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

      2. 键入以下命令以安装 Node.js 和 NPM:

      3. 酿造安装节点

      4. 查看节点版本:node -v

      5. 查看 npm 版本:npm -v

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-31
        • 2021-12-30
        • 2018-04-01
        • 2022-01-20
        • 2021-12-29
        • 1970-01-01
        • 1970-01-01
        • 2015-10-02
        相关资源
        最近更新 更多