Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.44k stars 2.62k forks source link

Stopped working in Heroku environment #5018

Open davidmeirlevy opened 3 years ago

davidmeirlevy commented 3 years ago

What's going wrong?

since a few days ago, pm2 stopped working in Heroku machines. I'm tried to use pm2 locally and globally, tried to revert to version 4.4.1, or 4.5.1, and upgraded to 4.5.5 - nothing works. The only way to run my app is to roll back into a previous version. It looks like that even if I'm running a new build with the same version that worked - it will not work again.

don't need to say it but I will - it works fine locally, and inside dockerized servers (tested the same code at digitalocean).

How could we reproduce this issue?

Run an app using PM2 on Heroku. the build will pass. after the build passed - see look at the runtime logs. you will get this error:

 internal/modules/cjs/loader.js:883
   throw err;
   ^
 Error: Cannot find module '@pm2/pm2-version-check'
 Require stack:
 - /app/node_modules/pm2/lib/VersionCheck.js
 - /app/node_modules/pm2/lib/Worker.js
 - /app/node_modules/pm2/lib/God.js
 - /app/node_modules/pm2/lib/Daemon.js
 - /app/node_modules/pm2/lib/Client.js
 - /app/node_modules/pm2/lib/API.js
 - /app/node_modules/pm2/index.js
 - /app/node_modules/pm2/lib/binaries/Runtime4Docker.js
 - /app/node_modules/pm2/bin/pm2-runtime
     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
     at Function.Module._load (internal/modules/cjs/loader.js:725:27)
     at Module.require (internal/modules/cjs/loader.js:952:19)
     at require (internal/modules/cjs/helpers.js:88:18)
     at Object.<anonymous> (/app/node_modules/pm2/lib/VersionCheck.js:2:14)
     at Module._compile (internal/modules/cjs/loader.js:1063:30)
     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
     at Module.load (internal/modules/cjs/loader.js:928:32)
     at Function.Module._load (internal/modules/cjs/loader.js:769:14)
     at Module.require (internal/modules/cjs/loader.js:952:19) {
   code: 'MODULE_NOT_FOUND',
   requireStack: [
     '/app/node_modules/pm2/lib/VersionCheck.js',
     '/app/node_modules/pm2/lib/Worker.js',
     '/app/node_modules/pm2/lib/God.js',
     '/app/node_modules/pm2/lib/Daemon.js',
     '/app/node_modules/pm2/lib/Client.js',
     '/app/node_modules/pm2/lib/API.js',
     '/app/node_modules/pm2/index.js',
     '/app/node_modules/pm2/lib/binaries/Runtime4Docker.js',
     '/app/node_modules/pm2/bin/pm2-runtime'
   ]
 }
 npm ERR! code ELIFECYCLE
 npm ERR! errno 1

Supporting information

node 14.6 npm 6.x

tried pm2 versions: 4.4.1, 4.5.1, 4.5.5 (versions with * installed both locally and globally, at both "preinstall" and "prestart" npm hooks.)

davidmeirlevy commented 3 years ago

It looks like it's not only me, but also other people that tried to deploy into Heroku in the last few weeks. I also see something strange in my logs, around this line: '/app/node_modules/pm2/lib/binaries/Runtime4Docker.js',

why did the pm2-runtime thought my app is inside a docker environment? I believe Heroku doesn't necessarily work with docker images.

davidmeirlevy commented 3 years ago

I managed to pass this issue on Heroku after I added this package to my own package.json: @pm2/pm2-version-check. It's probably a workaround, and I should probably maybe clear the node modules caching of Heroku once or twice to handle it perfectly, but it worked.

kendallroth commented 3 years ago

I also have been experiencing this, but do not have any preinstall and pre-start hooks. Similarly, PM2 is working as expected in a local Dockerized stack, but not in Heroku. I can confirm that install @pm2/pm2-version-check alleviates the problem as a workaround; any ideas what caused this?

markhealey commented 3 years ago

Experiencing the same issue! Just upgraded from 4.5.5 to 4.5.6 2 days ago and our app is no longer starting up on Heroku.

aubundy commented 3 years ago

Is there an update on this? I'm experiencing the same error with 5.1.0 and Heroku.

vintprox commented 3 years ago

Found a workaround for this, kindly provided here. Add in npm scripts:

"heroku-postbuild": "npm install pm2"