pm2意外的令牌导入 [英] pm2 Unexpected token import

查看:698
本文介绍了pm2意外的令牌导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用node或nodemon(例如"nodemon index.js")时,我有一个可以工作的网络服务器.但是,当我尝试使用pm2("pm2 start index.js")时,出现"SyntaxError:意外的令牌导入".完整的错误日志如下.我在这里做什么错了?

I have a webserver that works when I use node or nodemon (e.g. "nodemon index.js"). However, when I try to use pm2 ("pm2 start index.js"), I get "SyntaxError: Unexpected token import". The full error log is below. What am I doing wrong here?

/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:29
import(process.env.pm_exec_path);
^^^^^^

SyntaxError: Unexpected token import 
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (internal/modules/cjs/loader.js:618:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
at startup (internal/bootstrap/node.js:201:19)

推荐答案

遇到同样的问题.

pm2发布了4.2.2版,该版本仅适用于Node 10.x或更高版本,因此:

pm2 released version 4.2.2 which only works with Node 10.x or better, so:

最好的解决方案是将节点从9.x升级到10.x或更高版本.

Best solution is to upgrade your node from 9.x to 10.x or better.

在我的情况下,我想坚持使用节点9,因此将pm2的版本固定为4.2.1.

In my case I wanted to stick to node 9 so I fixed the version of pm2 to version 4.2.1

我使用npm在我的Dockerfile中安装pm2:

I use npm to install pm2 in my Dockerfile:

更改:

RUN npm install -g webpack@4.29.3 pm2

收件人:

RUN npm install -g webpack@4.29.3 pm2@4.2.1

将解决此问题,并允许您继续使用节点9和pm2 4.2.1

Will fix the issue and allow you to continue working with node 9 and pm2 4.2.1

如果您以其他方式安装pm2,请发布安装详细信息,我可以建议如何修复.

If you install pm2 in some other way post your install details and I can recommend how to fix.

这篇关于pm2意外的令牌导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆