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 #4588

Closed
krystianjj opened this issue Jan 21, 2020 · 10 comments
Closed

SyntaxError: Unexpected token import #4588

krystianjj opened this issue Jan 21, 2020 · 10 comments

Comments

@krystianjj
Copy link

krystianjj commented Jan 21, 2020

What's going wrong?

When try to run pm2 start server.js I have error

    import(process.env.pm_exec_path);
    ^^^^^^
SyntaxError: Unexpected token import
    at new Script (vm.js:51:7)
    at createScript (vm.js:138:10)
    at Object.runInThisContext (vm.js:199:10)
    at Module._compile (module.js:624:28)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:193:16)
/usr/local/node/node-

How could we reproduce this issue?

Start pm2 with latest version

Supporting information

Until today morning everything working great. I see that yesterday pm2 was updated to version 4.2.2

$ pm2 report
--- PM2 report ----------------------------------------------------------------
Date                 : Tue Jan 21 2020 12:12:00 GMT+0100 (CET)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.2.2
node version         : 9.4.0
node path            : /usr/local/node/node-default/bin/pm2
argv                 : /usr/local/node/node-v9.4.0/bin/node,/usr/local/node/node-v9.4.0/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
uptime               : 129min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.2.2
node version         : 9.4.0
node path            : /usr/local/node/node-default/bin/pm2
argv                 : /usr/local/node/node-v9.4.0/bin/node,/usr/local/node/node-default/bin/pm2,report
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
cpus nb              : 2
freemem              : 423391232
totalmem             : 1887514624
home                 : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name   │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ WEB    │ default     │ 0.1.0   │ fork    │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ root     │ disabled │
└─────┴────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] starting in -fork mode-
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] online
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] starting in -fork mode-
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] online
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] starting in -fork mode-
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] online
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] starting in -fork mode-
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] online
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] starting in -fork mode-
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] online
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] starting in -fork mode-
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] online
PM2        | 2020-01-21T10:02:42: PM2 log: App [WEB:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-21T10:02:42: PM2 log: Script /var/www/html/vhost-service0/server.js had too many unstable restarts (16). Stopped. "errored"

@Unitech
Copy link
Owner

Unitech commented Jan 21, 2020

Fixed thanks for reporting

npm install pm2 -g
pm2 update

@Unitech Unitech closed this as completed Jan 21, 2020
@krystianjj
Copy link
Author

Great, thanks!

@szkrd
Copy link

szkrd commented Feb 9, 2020

Is it possible that when I'm using pm2 from the command line the --interpreter version (below v10) still affects this? The pm2 execution context is v10.19.0, but I'm trying to use node v6, and I still have an import error:

image

inerc pushed a commit to inerc/pm2 that referenced this issue Feb 11, 2020
@petr166
Copy link

petr166 commented Feb 19, 2020

@Unitech I have a similar issue as @szkrd. I'm running node@12.4.1 and trying to start a process with interpreter: 'node@8.17.0'. This results in the import error

@jonluca
Copy link

jonluca commented Feb 24, 2020

I am still seeing this issue with pm2 v4.2.3

3|SOC2  | 2020-02-23T17:24:35.463: /home/jonluca/.nvm/versions/node/v13.8.0/lib/node_modules/pm2/lib/ProcessContainerFork.js:29
3|SOC2  | 2020-02-23T17:24:35.463:     import(process.env.pm_exec_path);
3|SOC2  | 2020-02-23T17:24:35.463:     ^^^^^^
3|SOC2  | 2020-02-23T17:24:35.463:
3|SOC2  | 2020-02-23T17:24:35.463: SyntaxError: Unexpected token import
3|SOC2  | 2020-02-23T17:24:35.463:     at new Script (vm.js:51:7)
3|SOC2  | 2020-02-23T17:24:35.463:     at createScript (vm.js:136:10)
3|SOC2  | 2020-02-23T17:24:35.463:     at Object.runInThisContext (vm.js:197:10)
3|SOC2  | 2020-02-23T17:24:35.463:     at Module._compile (module.js:626:28)
3|SOC2  | 2020-02-23T17:24:35.463:     at Object.Module._extensions..js (module.js:673:10)
3|SOC2  | 2020-02-23T17:24:35.463:     at Module.load (module.js:575:32)
3|SOC2  | 2020-02-23T17:24:35.463:     at tryModuleLoad (module.js:515:12)
3|SOC2  | 2020-02-23T17:24:35.463:     at Function.Module._load (module.js:507:3)
3|SOC2  | 2020-02-23T17:24:35.463:     at Function.Module.runMain (module.js:703:10)
3|SOC2  | 2020-02-23T17:24:35.463:     at startup (bootstrap_node.js:193:16)

These are simple applications started with a pm2.config.js file that looks like:

module.exports = {
  /**
   * Application configuration section
   * http://pm2.keymetrics.io/docs/usage/application-declaration/
   */
  apps: [// First application
    {
      name: 'SOC2',
      script: 'bin/www',
      log_date_format: 'YYYY-MM-DDTHH:mm:ss.SSS',
      env: {
        NODE_ENV: 'production'
      }
    }

  ]
};

@jonluca
Copy link

jonluca commented Feb 24, 2020

@Unitech I was able to temporarily fix this by changing lib/God.js and lib/God/ForkMode.js to always load the legacy version

/**
 * Override cluster module configuration
 */
cluster.setupMaster({
    windowsHide: true,
    exec : path.resolve(path.dirname(module.filename), 'ProcessContainerLegacy.js')
  });

This is on Node v13.9.0

@jubarbie
Copy link

I am also experiencing the same issue, I'm running node v12.0.0 and PM2 4.2.3.
Can someone help ? I'm unable to load my app

@szkrd
Copy link

szkrd commented Mar 11, 2020

@Unitech can you reopen this, or should it be a different issue? I enforced the two affected microservices I work with to node 10 in the end, but it seems to be that others might experience the same issue.

@krystianjj
Copy link
Author

Can you show the error log and pm2 report ?

@szkrd
Copy link

szkrd commented Mar 11, 2020

@krystianjj I attached two > dumps, but since I'm now fine on node 10 with the offending microservices, maybe others should come forward... nevertheless, here they are:
log-6.txt
report.txt

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

No branches or pull requests

6 participants