New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`exec_interpreter` ignored, can't use `babel-node` #1643

Closed
xpepermint opened this Issue Sep 25, 2015 · 19 comments

Comments

6 participants
@xpepermint

xpepermint commented Sep 25, 2015

I can not get this to work (v0.15.6). The exec_interpreter is always ignored. Suggestions?

{
  "apps": [
    {
      "name": "myapp",
      "script": "scripts/app.js",
      "exec_interpreter": "./node_modules/.bin/babel-node",
      "exec_mode": "cluster_mode",
      "instances": 0,
      "merge_logs": true
    }
  ],
  "deploy": {
    "production": {
      "user": "worker",
      "host": "XX.XX.XX.XX",
      "ref": "origin/master",
      "repo": "git@...",
      "path": "/home/worker/...",
      "post-deploy": "npm install && pm2 startOrRestart package.json"
    }
  }
}

Log error:

/home/worker/app/source/scripts/tracker.js:1
(function (exports, require, module, __filename, __dirname) { import app f
                                                              ^^^^^^
SyntaxError: Unexpected reserved word
@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Sep 25, 2015

Collaborator

You can't use cluster with a custom interpreter.

Collaborator

soyuka commented Sep 25, 2015

You can't use cluster with a custom interpreter.

@xpepermint

This comment has been minimized.

Show comment
Hide comment
@xpepermint

xpepermint Sep 25, 2015

Crap! What should I do? Two processes like apps[app1, app2]?

xpepermint commented Sep 25, 2015

Crap! What should I do? Two processes like apps[app1, app2]?

@Jastrzebowski

This comment has been minimized.

Show comment
Hide comment
@Jastrzebowski

Jastrzebowski Sep 29, 2015

@xpepermint @soyuka any workaround? With next_gen_js it was working fine on iojs in cluster mode :/

Jastrzebowski commented Sep 29, 2015

@xpepermint @soyuka any workaround? With next_gen_js it was working fine on iojs in cluster mode :/

@xpepermint

This comment has been minimized.

Show comment
Hide comment
@xpepermint

xpepermint Sep 29, 2015

Well... --next-gen-js option has been removed :(. I hope someone finds a solution. Maybe node v4 will support ES6 import/export modules soon.

xpepermint commented Sep 29, 2015

Well... --next-gen-js option has been removed :(. I hope someone finds a solution. Maybe node v4 will support ES6 import/export modules soon.

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Sep 29, 2015

Collaborator

A workaround would be to use babeljs require hook in your entry point.

This is untested but should work (this is what --next-gen-js was doing under the hood):

Assuming index.js, server.js:

index.js

require('babel/register')
require('./server.js')

server.js

import p from 'path'

And start the app with : pm2 start index.js

Just my two cents about babel:

I think it's too heavy to be implemented in a project that has to be deployed/packed. It has a lot of dependencies, and you'd have to babelize your code before you could ship it on npm (so that require('yourpackage') works without babel). Also, node 4.0 is already supporting plenty of harmony features. For example arrow functions, .find, .findIndex etc. are working with --harmony. By using the strict mode you'd access to let, const etc.. Unless you're absolutely in love with the import/export features, you may not need babel ;).

Collaborator

soyuka commented Sep 29, 2015

A workaround would be to use babeljs require hook in your entry point.

This is untested but should work (this is what --next-gen-js was doing under the hood):

Assuming index.js, server.js:

index.js

require('babel/register')
require('./server.js')

server.js

import p from 'path'

And start the app with : pm2 start index.js

Just my two cents about babel:

I think it's too heavy to be implemented in a project that has to be deployed/packed. It has a lot of dependencies, and you'd have to babelize your code before you could ship it on npm (so that require('yourpackage') works without babel). Also, node 4.0 is already supporting plenty of harmony features. For example arrow functions, .find, .findIndex etc. are working with --harmony. By using the strict mode you'd access to let, const etc.. Unless you're absolutely in love with the import/export features, you may not need babel ;).

@xpepermint

This comment has been minimized.

Show comment
Hide comment
@xpepermint

xpepermint Sep 29, 2015

@soyuka thanks for the proposal. Yeah... I'm in love with import/export feature but maybe I'll change that. I think I still have other issues because I need to execute my scripts through npm to use npm-config (#1317 (comment)). Is that possible with exec_interpreter + cluster mode?

xpepermint commented Sep 29, 2015

@soyuka thanks for the proposal. Yeah... I'm in love with import/export feature but maybe I'll change that. I think I still have other issues because I need to execute my scripts through npm to use npm-config (#1317 (comment)). Is that possible with exec_interpreter + cluster mode?

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Sep 29, 2015

Collaborator

@xpepermint I can't answer to this issue as I'm not familiar with the deployment feature sorry :/. Not sure that what you're trying to do is possible though.

Collaborator

soyuka commented Sep 29, 2015

@xpepermint I can't answer to this issue as I'm not familiar with the deployment feature sorry :/. Not sure that what you're trying to do is possible though.

@xpepermint

This comment has been minimized.

Show comment
Hide comment
@xpepermint

xpepermint Sep 29, 2015

@soyuka humm... ok thx.

xpepermint commented Sep 29, 2015

@soyuka humm... ok thx.

@Jastrzebowski

This comment has been minimized.

Show comment
Hide comment
@Jastrzebowski

Jastrzebowski Sep 29, 2015

@soyuka entry point trick works great, thanks :)

I agree that Babel as an dependency was an overload, but using an external interpreter in cluster mode would be really helpful.

Jastrzebowski commented Sep 29, 2015

@soyuka entry point trick works great, thanks :)

I agree that Babel as an dependency was an overload, but using an external interpreter in cluster mode would be really helpful.

@xpepermint

This comment has been minimized.

Show comment
Hide comment
@xpepermint

xpepermint Sep 29, 2015

It would be great if we could have --next-gen-js until node4 ES6 implementation is complete.

xpepermint commented Sep 29, 2015

It would be great if we could have --next-gen-js until node4 ES6 implementation is complete.

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Sep 29, 2015

Collaborator

I agree that Babel as an dependency was an overload, but using an external interpreter in cluster mode would be really helpful.

Nope it can't work because the cluster mode doesn't work like a interpreter.

When using the fork mode, pm2 juste uses a custom implementation of child_process.fork. The interpreter becomes the binary that is forked (with some stuff on top of it so that pm2 can interact with the forked process).

On the other way with the cluster mode with are using cluster which is not related to the child_process and can, obviously, only work with node.
This is not 100% true because nodejs uses child_process.fork in cluster.fork but it doesn't allow passing parameters to the cluster. If it would it won't change much because cluster is using IPC, and transfering javascript objects is only possible between javascript interpreters.

@xpepermint we removed the --next-gen-js because babel is too heavy, in the mean time you can use the fork mode with babel-node interpreter ;)

Collaborator

soyuka commented Sep 29, 2015

I agree that Babel as an dependency was an overload, but using an external interpreter in cluster mode would be really helpful.

Nope it can't work because the cluster mode doesn't work like a interpreter.

When using the fork mode, pm2 juste uses a custom implementation of child_process.fork. The interpreter becomes the binary that is forked (with some stuff on top of it so that pm2 can interact with the forked process).

On the other way with the cluster mode with are using cluster which is not related to the child_process and can, obviously, only work with node.
This is not 100% true because nodejs uses child_process.fork in cluster.fork but it doesn't allow passing parameters to the cluster. If it would it won't change much because cluster is using IPC, and transfering javascript objects is only possible between javascript interpreters.

@xpepermint we removed the --next-gen-js because babel is too heavy, in the mean time you can use the fork mode with babel-node interpreter ;)

@xpepermint

This comment has been minimized.

Show comment
Hide comment
@xpepermint

xpepermint commented Sep 29, 2015

@soyuka thx!

@Jastrzebowski

This comment has been minimized.

Show comment
Hide comment
@Jastrzebowski

Jastrzebowski Sep 30, 2015

thx @soyuka for in-depth explanation, last question, could next-gen-js be moved somehow to a separate plugin?

Jastrzebowski commented Sep 30, 2015

thx @soyuka for in-depth explanation, last question, could next-gen-js be moved somehow to a separate plugin?

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Sep 30, 2015

Collaborator

Not really because to work with the cluster it'd require to have babel/register in the processContainer. You can use the above workaround in your application it'll work just fine ;).

Adding require('babel/register') to your pm2 entry point will do the exact same job ;).

Collaborator

soyuka commented Sep 30, 2015

Not really because to work with the cluster it'd require to have babel/register in the processContainer. You can use the above workaround in your application it'll work just fine ;).

Adding require('babel/register') to your pm2 entry point will do the exact same job ;).

@asendia

This comment has been minimized.

Show comment
Hide comment
@asendia

asendia Oct 3, 2015

@soyuka I was panicking when I ran npm install pm2@latest -g ; pm2 update on our staging server and the app suddenly stopped working. Btw, thanks for the workaround info!

asendia commented Oct 3, 2015

@soyuka I was panicking when I ran npm install pm2@latest -g ; pm2 update on our staging server and the app suddenly stopped working. Btw, thanks for the workaround info!

@zlbbq

This comment has been minimized.

Show comment
Hide comment
@zlbbq

zlbbq Oct 18, 2015

Suggestion : install pm2@0.14.7 to use babel-node until V8 ES6 implementation is complete.

zlbbq commented Oct 18, 2015

Suggestion : install pm2@0.14.7 to use babel-node until V8 ES6 implementation is complete.

@agonbina

This comment has been minimized.

Show comment
Hide comment
@agonbina

agonbina Nov 8, 2015

The suggested solution with babel/register doesn't work with pm2. First of all its no longer babel, but the package seems to be named babel-core from which you should require. Second, this works if you just run babel-node index.js but setting babel-node as the interpreter via pm2 doesn't seem to be working.

agonbina commented Nov 8, 2015

The suggested solution with babel/register doesn't work with pm2. First of all its no longer babel, but the package seems to be named babel-core from which you should require. Second, this works if you just run babel-node index.js but setting babel-node as the interpreter via pm2 doesn't seem to be working.

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Nov 8, 2015

Collaborator

The register hook just works https://babeljs.io/docs/usage/require/

Le dim. 8 nov. 2015 à 10:28, Agon Bina notifications@github.com a écrit :

The suggested solution with babel/register doesn't work with pm2. First of
all its no longer babel, but the package seems to be named babel-core
from which you should require. Second, this works if you just run babel-node
index.js but setting babel-node as the interpreter via pm2 doesn't seem
to be working.


Reply to this email directly or view it on GitHub
#1643 (comment).

Collaborator

soyuka commented Nov 8, 2015

The register hook just works https://babeljs.io/docs/usage/require/

Le dim. 8 nov. 2015 à 10:28, Agon Bina notifications@github.com a écrit :

The suggested solution with babel/register doesn't work with pm2. First of
all its no longer babel, but the package seems to be named babel-core
from which you should require. Second, this works if you just run babel-node
index.js but setting babel-node as the interpreter via pm2 doesn't seem
to be working.


Reply to this email directly or view it on GitHub
#1643 (comment).

@soyuka

This comment has been minimized.

Show comment
Hide comment
@soyuka

soyuka Mar 8, 2016

Collaborator

Following up in #2005

Collaborator

soyuka commented Mar 8, 2016

Following up in #2005

@soyuka soyuka closed this Mar 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment