Skip to content
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

SyntaxError: Unexpected token import when starting with --interpreter node<10 #4686

Closed
kimmobrunfeldt opened this issue Apr 24, 2020 · 5 comments

Comments

@kimmobrunfeldt
Copy link

kimmobrunfeldt commented Apr 24, 2020

What's going wrong?

This is a follow-up issue after #4588. It seems that the issue didn't address this use case and that's why I created a new one.

I'm using node@10.8.0 to launch pm2. When starting a project which requires older node version 6.9.4, pm2 fails.

I'm starting with command: pm2 start index.js --interpreter ~/.nvm/versions/node/v6.9.4/bin/node. Process starts but goes to errored state immediately, logs show the following error:

0|index    | /Users/kimmo/.nvm/versions/node/v10.8.0/lib/node_modules/pm2/lib/ProcessContainerFork.js:29
0|index    |     import(process.env.pm_exec_path);
0|index    |     ^^^^^^
0|index    | SyntaxError: Unexpected token import
0|index    |     at Object.exports.runInThisContext (vm.js:76:16)
0|index    |     at Module._compile (module.js:542:28)
0|index    |     at Object.Module._extensions..js (module.js:579:10)
0|index    |     at Module.load (module.js:487:32)
0|index    |     at tryModuleLoad (module.js:446:12)
0|index    |     at Function.Module._load (module.js:438:3)
0|index    |     at Module.runMain (module.js:604:10)
0|index    |     at run (bootstrap_node.js:394:7)
0|index    |     at startup (bootstrap_node.js:149:9)
0|index    |     at bootstrap_node.js:509:3

How could we reproduce this issue?

nvm install 6.9.4
nvm install 10.8.0
nvm use 10.8.0
npm install -g pm2

echo "console.log('test')" > index.js

pm2 start index.js --interpreter ~/.nvm/versions/node/v6.9.4/bin/node

Using an absolute path for the interpreter had same effect.

This was also reproduced with pm2 start index.js --interpreter ~/.nvm/versions/node/v8.12.0/bin/node. I suspect it happens with all node versions under 10 based on the other issue comments.

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Fri Apr 24 2020 11:30:23 GMT+0300 (Eastern European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.4.0
node version         : 10.8.0
node path            : /Users/kimmo/.nvm/versions/node/v10.8.0/bin/pm2
argv                 : /Users/kimmo/.nvm/versions/node/v10.8.0/bin/node,/Users/kimmo/.nvm/versions/node/v10.8.0/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : kimmo
uid                  : 501
gid                  : 20
uptime               : 3min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.4.0
node version         : 10.8.0
node path            : /Users/kimmo/.nvm/versions/node/v10.8.0/bin/pm2
argv                 : /Users/kimmo/.nvm/versions/node/v10.8.0/bin/node,/Users/kimmo/.nvm/versions/node/v10.8.0/bin/pm2,report
argv0                : node
user                 : kimmo
uid                  : 501
gid                  : 20
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : darwin
type                 : Darwin
cpus                 : Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
cpus nb              : 8
freemem              : 316932096
totalmem             : 17179869184
home                 : /Users/kimmo
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬──────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name     │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ index    │ default     │ 1.0.0   │ fork    │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ kimmo    │ disabled │
└─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/kimmo/.pm2/pm2.log last 20 lines:
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] online
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] online
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] online
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] online
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] online
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] online
PM2        | 2020-04-24T11:26:50: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-04-24T11:26:50: PM2 log: Script /Users/kimmo/code/alvarcarto/pm2-issue/index.js had too many unstable restarts (16). Stopped. "errored"

@Unitech
Copy link
Owner

Unitech commented Apr 24, 2020

Use pm2 3.x

npm install pm2@3 -g

@Unitech Unitech closed this as completed Apr 24, 2020
@vnen
Copy link

vnen commented May 30, 2020

So the only solution to launch process with node<10 is to stay on an old pm2 version?

@Fabryz
Copy link

Fabryz commented Jun 30, 2020

I've just installed PM2 4.4.0 and I have this issue too.
Using Node v12.17.0 on nvm, with MacOS.
Was launching:
pm2-runtime start ecosystem.config.js --env development

launching with this seem to work fine:
pm2 start script.js

@Fabryz
Copy link

Fabryz commented Jul 1, 2020

I've just installed PM2 4.4.0 and I have this issue too.
Using Node v12.17.0 on nvm, with MacOS.
Was launching:
pm2-runtime start ecosystem.config.js --env development

launching with this seem to work fine:
pm2 start script.js

Looks like I was using the wrong nodejs version on the interpreter field in the ecosystem.config.js file. 👍

@soberirving
Copy link

使用 pm2 3.x

npm install pm2@3 -g

thanks!node9.0.0+pm2v3.5.0 are well matched,and it would be better if you could provide a matching list on the homepage!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants