【问题标题】:SyntaxError when trying to do anything in npm尝试在 npm 中执行任何操作时出现 SyntaxError
【发布时间】:2018-10-27 22:48:44
【问题描述】:

我回到了很久没用过的 Win10 电脑。首先,我尝试用

更新npm
> npm i npm -g

我收到了这个:

added 290 packages, removed 250 packages and updated 37 packages in 38.815s
   ╭─────────────────────────────────────╮
   │                                     │
   │   Update available 5.0.0 → 6.4.1    │
   │     Run npm i -g npm to update      │
   │                                     │
   ╰─────────────────────────────────────╯

然后,我尝试运行npm i -g npm 并得到:

     let notifier = require('update-notifier')({pkg})
      ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3

现在当我尝试做任何事情时,我得到了同样的错误。如果您想知道我正在尝试从 npm 5.0.0 更新到 6.4.1


我尝试过的事情

我用谷歌搜索了这个错误,发现如下:

  • Update Node

    • these instructions 之后,我首先尝试使用npm cache clean -f 清除npm 的缓存,但得到了相同的SyntaxError
    • 同样的说明还说要用 nvm 做一些我没有的东西,所以我尝试用 npm i nvm -g 安装它,但同样的错误。
  • use strict,尽管我知道这是针对使用节点的程序。我想确保在发布问题之前我已经尝试了所有方法。

    • '"use strict"' is not recognized as an internal or external command, operable program or batch file.
  • Fresh npm install of webpack.js is throwing Block-scope error 但这似乎不适用于我,因为我没有使用 Visual Studio,而且我没有使用 babel 或 webpack 或 es6 做任何事情。我只是想更新 npm。

【问题讨论】:

    标签: npm


    【解决方案1】:

    我找不到任何答案,所以我决定使用以下说明完全卸载 node 和 npm:https://stackoverflow.com/a/20711410/1152809

    然后我重新安装了节点,一切都按预期工作。

    【讨论】:

      猜你喜欢
      • 2019-09-26
      • 2019-07-01
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 2020-07-30
      相关资源
      最近更新 更多