I have server code written in ES6, and I use pm2 to manage that server. A few months ago, I used the next_gen_js
option and it worked magically.
However, I now tried to update pm2 to v1.0.0, and I get errors about import
being an illegal token. Basically, my ES6 files are not parsed as ES6 anymore.
What can I do to use pm2 with ES6 files?
pm2 dropped the next_gen_js
flag in v1.0.0, because it bundled babel, which was quite heavy.
You basically have four options.
next_gen_js
flag. interpreter
(alias of exec_interpreter
) flag and set it to babel-node
. You'll need to add babel-cli
as a dependency of your app. Note that the interpreter
option is compatible only with the fork
exec_mode
, not with cluster
. This option being still in beta at the time of writing, this might not be a major issue unless you have important scaling constraints. babel-register
. For example, you might have a server.js
file that's in ES6 and the preferred entry point for ES6-compatible engines, and an index.js
that only does require('babel-register'); require('./server');
require('babel-register'); require('./server');
. 从文档( http://pm2.keymetrics.io/docs/usage/quick-start/ )中,您只需使用以下解释器标签启动pm2即可:
pm2 start --interpreter babel-node server.js //(server.es6)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.