pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Cannot use pm2 with node and 'esm' option

Open dhowe opened this issue 6 years ago • 8 comments

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

dhowe avatar Jan 20 '20 04:01 dhowe

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

dhowe avatar Jan 23 '20 07:01 dhowe

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.

i2dcarrasco avatar Feb 28 '20 11:02 i2dcarrasco

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

nonken avatar Mar 21 '20 19:03 nonken

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
  }]
};

dhowe avatar Mar 22 '20 03:03 dhowe

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.

stale[bot] avatar May 23 '20 19:05 stale[bot]

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'.

mo18 avatar May 26 '20 21:05 mo18

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.

stale[bot] avatar Jun 25 '20 22:06 stale[bot]

This issue still present in 5.2.0 pm2 works fine until I reboot the server. After the reboot, the error is Error: Cannot find module 'esm'

Error: Cannot find module 'esm' Require stack:

  • internal/preload at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) at Function.Module._load (internal/modules/cjs/loader.js:746:27) at Module.require (internal/modules/cjs/loader.js:974:19) at Module._preloadModules (internal/modules/cjs/loader.js:1244:12) at loadPreloadModules (internal/bootstrap/pre_execution.js:475:5) at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:72:3) at internal/main/run_main_module.js:7:1 { code: 'MODULE_NOT_FOUND', requireStack: [ 'internal/preload' ] }

pm2 starting in cluster mode.

Only this helps npm uninstall -g pm2 rm -r ~/.pm2 npm install -g pm2

After the that, pm2 worked again with esm.

Is there a way not do this after every reboot?

a2exfr avatar Jul 26 '22 22:07 a2exfr