【问题标题】:Node-js SyntaxError running npm运行 npm 的 Node-js SyntaxError
【发布时间】:2020-09-23 15:50:07
【问题描述】:

每当我运行任何“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:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

我的节点版本

node -v
> v4.2.6

我相信最新的是 14,但我也无法更新它。

我试过跑步

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

然后,

sudo apt-get install -y nodejs
>Reading package lists... Done
Building dependency tree       
Reading state information... Done
nodejs is already the newest version (4.2.6~dfsg-1ubuntu4.2).
0 upgraded, 0 newly installed, 0 to remove and 50 not upgraded.

【问题讨论】:

  • curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - 是成功了还是失败了?
  • 好像成功了。最后它说 ## Run sudo apt-get install -y nodejs 安装 Node.js 12.x 和 npm

标签: node.js linux ubuntu npm node-modules


【解决方案1】:

你不能在严格模式下使用 let ,const。所以要么使用严格模式,要么使用“var”而不是“let”。

【讨论】:

  • 我的意思是在你的代码中有一行所以检查并编辑它。控制台向您显示错误在该行中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-17
  • 1970-01-01
  • 2022-01-23
  • 2015-11-15
  • 2021-11-17
相关资源
最近更新 更多