我目前正在 Ubuntu 服务器上安装 NodeJS 服务。该应用程序是用 CoffeeScript 编写的,并且可以自行运行良好。这就是我设置项目的方式:
cd ~/test-project
nvm use v4.9.1
npm install
pm2 start index.js
但是,当我尝试使用 pm2 启动它时,出现以下错误:
/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/node.js:132
let val = process.env[key];
^^^
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 Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/needle/node_modules/debug/src/index.js:9:19)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
经过一些测试后,无论我用 pm2 启动哪个脚本,似乎都会发生此错误,因此一定有某些内容配置不正确..
我不知道这是否重要,但我尝试运行的脚本需要 Node v4.9.1,所以我使用 NVM 来使用该版本,在我看来,它正在尝试使用相同的 Node 版本运行 pm2不知何故?
非常感谢您的任何意见,因为我已经在这个问题上坚持了太久了!!
最佳答案
我在 Node 版本 4.x 上遇到了同样的问题,
降级 pm2 并成功。
npm uninstall -g pm2
npm install -g <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72021f4032415c425c46" rel="noreferrer noopener nofollow">[email protected]</a>
关于node.js - PM2 - 语法错误 : Block-scoped declarations not yet supported outside strict mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55842552/