It would be nice to execute a Node app with PM2 executing node with Babel
https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#a23
Use Babel as an exec interpreter it should work :)
Le lun. 13 avr. 2015 Ã 17:27, Michael Gunnulfsen [email protected]
a écrit :
It would be nice to execute a Node app with PM2 executing node with Babel
—
Reply to this email directly or view it on GitHub
https://github.com/Unitech/PM2/issues/1167.
Yes! I tried this earlier, but I guess I had an old version of pm2. Thanx!
@sslash do you have a working example? --interpreter babel-node doesn't work for me.
I have tried pm2 start app.js -x babel-node
It's not use +1
Try upgrading babel-node. Remember to upgrade your global version if you run your global babel-node. Might also try upgrading pm2
➜ midway-ci git:(develop) ✗ babel --version
5.1.11
➜ midway-ci git:(develop) ✗ babel-node --version
5.1.11
➜ midway-ci git:(develop) ✗ pm2 -v
0.12.12
➜ midway-ci git:(develop) ✗ pm2 start app.js -x babel-node
not use yet :cry:
any update?
@haohcraft, Get done:
pm2 start app.js --interpreter ./node_modules/.bin/babel-node
note that --interpreter can't work in cluster mode (-i) due to its operating principle...
pm2 start app.js -i 0 --next-gen-js done! (DEPRECATED)
Not working for me with the "--next-gen-js" I've also trie the "pm2 start app.js --interpreter babel-node" approach and im getting issues with the interpreter not picking up arrow functions and syntax like var [foo, bar] = require('Something')
Hi, can you give us a code sample (which is not working) please ?
My bad it works now with the "-i 0" flag
For anyone else.
"pm2 start app.js -i 0 --next-gen-js --interpreter iojs"
@arnold-almeida the -i flag shouldn't make a difference, it's not related to Babel/ES next.
Does this add sourcemap support within babel?
Is there a way to pass arguments to babel?
Does this add sourcemap support within babel?
@michaelBenin isn't this something babel-node does for you? I think pm2 uses babel-node under the hood.
Is there a way to pass arguments to babel?
Just as you'd do with node, my guess is by using node_args but I haven't tested it.
You can use the babel/register module for this.
serverapp.js
require('babel/register')({
stage: 1 // for es 7 features
})
var server = require('./server.babel.js')
server.start()
Start it with pm2
pm2 start serverapp.js
Note that this is fine to do for running processes. But it adds to your startup time as every required script gets compiled. So one-off scripts started with pm2 should be precompiled.
works for me on ubuntu 14.04
Testing on Ubuntu 16.04 with latest version and its not working for me.
I'm trying with the pm2 start --interpreter babel-node server.js
and nothing... it still doesn't know what to do with import
{
"name": "ESServer",
"script": "/usr/bin/npx",
"args": "babel-node ./server.js"
}
"--interpreter" doesn't work for me... even with require("babel-register")..
I'm using the ecosystem.config.js file to start the server testing.
Any suggestions??
Solved installing babel-preset-env and adding
"interpreter": "./node_modules/babel-cli/bin/babel-node.js",
"interpreter_args": "--harmony",
In the configuration file of pm2.
And adding in the .babelrc:
{
"presets": ["env"]
}
Earlier it was mentioned that --interpreter can't work with cluster mode, is that still true?
Earlier it was mentioned that --interpreter can't work with cluster mode, is that still true?
Yeah, i didn't found the way to user interpreter with cluster mode.
if we can't use the --interpreter on a cluster mode, then what we can do to run our es6 and higher versions of ECMAScript within our cluster mode pm2?
Most helpful comment
@haohcraft, Get done:
pm2 start app.js --interpreter ./node_modules/.bin/babel-node