Pm2: Cannot use pm2 with node and 'esm' option

Created on 20 Jan 2020  ยท  7Comments  ยท  Source: Unitech/pm2

Script runs fine from terminal, but will not run via pm2.

Launched via $ pm2 start ecosystem.config.js, with config:

module.exports = {
  apps : [{
    name: 'app-server',
    script: 'server.js',
    instances: 1,
    node_args: '--required=esm',
    autorestart: true,
    watch: true,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production'
    }
  }]
};
--- PM2 report ----------------------------------------------------------------
Date                 : Mon Jan 20 2020 12:48:32 GMT+0800 
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.2.1
node version         : 12.9.1
node path            : /Users/mono1/.config/yarn/global/node_modules/pm2/bin/pm2
argv                 : /Users/mono1/.nvm/versions/node/v12.9.1/bin/node,/Users/mono1/.config/yarn/global/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : mono1
uid                  : 501
gid                  : 20
uptime               : 19min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.2.1
node version         : 12.9.1
node path            : /usr/local/Homebrew/bin/pm2
argv                 : /Users/mono1/.nvm/versions/node/v12.9.1/bin/node,/usr/local/Homebrew/bin/pm2,report
argv0                : node
user                 : dhowe
uid                  : 501
gid                  : 20
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : darwin
type                 : Darwin
cpus                 : Intel(R) Core(TM) i3-8100B CPU @ 3.60GHz
cpus nb              : 4
freemem              : 2399825920
totalmem             : 8589934592
home                 : /Users/mono1
===============================================================================
--- PM2 list -----------------------------------------------
โ”Œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ id โ”‚ name               โ”‚ mode     โ”‚ โ†บ    โ”‚ status    โ”‚ cpu      โ”‚ memory   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 0  โ”‚ spectre-server     โ”‚ cluster  โ”‚ 4788 โ”‚ errored   โ”‚ 0%       โ”‚ 0b       โ”‚
โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
===============================================================================
--- Daemon logs --------------------------------------------
/Users/mono1/.pm2/pm2.log last 20 lines:
PM2        | internal/modules/cjs/loader.js:775
PM2        |     throw err;
PM2        |     ^
PM2        | 
PM2        | Error: Cannot find module 'esm'
PM2        | Require stack:
PM2        | - internal/preload
PM2        |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
PM2        |     at Function.Module._load (internal/modules/cjs/loader.js:677:27)
PM2        |     at Module.require (internal/modules/cjs/loader.js:830:19)
PM2        |     at Module._preloadModules (internal/modules/cjs/loader.js:1099:12)
PM2        |     at loadPreloadModules (internal/bootstrap/pre_execution.js:419:5)
PM2        |     at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:54:3)
PM2        |     at internal/main/run_main_module.js:7:1 {
PM2        |   code: 'MODULE_NOT_FOUND',
PM2        |   requireStack: [ 'internal/preload' ]
PM2        | }
PM2        | 2020-01-20T12:32:33: PM2 log: App name:spectre-server id:0 disconnected
PM2        | 2020-01-20T12:32:33: PM2 log: App [spectre-server:0] exited with code [1] via signal [SIGINT]
PM2        | 2020-01-20T12:32:33: PM2 log: Script /Users/mono1/git/spectre/server.js had too many unstable restarts (16). Stopped. "errored"

Please copy/paste the above report in your issue on https://github.com/Unitech/pm2/issues

stale

Most helpful comment

I was able to solve this with the following ecosystem.config.js file (I believe it has to do with the 'instances' arg):

module.exports = {
  apps : [{
    name: 'app-server',
    log_file: 'server.log',
    script: 'server.js',
    node_args: '--require=esm',
    autorestart: true,
    watch: false
  }]
};

All 7 comments

I can only get the script to load by deleting the 'instances' option

Same problem here... When I run the script in cluster mode it runs until I reboot the machine. After that I have to remove the entire /root/.pm2 to make it work again, and I've got the same errors.

Best regards.

I am also experiencing this when redeploying an application with AWS CodeDeploy.

I was able to solve this with the following ecosystem.config.js file (I believe it has to do with the 'instances' arg):

module.exports = {
  apps : [{
    name: 'app-server',
    log_file: 'server.log',
    script: 'server.js',
    node_args: '--require=esm',
    autorestart: true,
    watch: false
  }]
};

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hello, I'm having the same issue. pm2 works fine until I reboot the server. After the reboot, the error is Error: Cannot find module 'esm'.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ldarren picture ldarren  ยท  3Comments

cchan picture cchan  ยท  3Comments

rangercyh picture rangercyh  ยท  4Comments

psparago picture psparago  ยท  3Comments

ghost picture ghost  ยท  3Comments