Closed gkentr closed 2 months ago
After some searching I figured this out - when I was trying to run the server script via node I was getting a similar error as this issue, which led me to this post. Basically you have to run the script directly, like so:
{
"script": "index.js",
"interpreter_args": "--require ./.pnp.cjs --loader ./.pnp.loader.mjs"
}
In the "real" project where I have been trying to use this, part of my problem was also that the PnP script was trying to resolve modules from a global cache (which I needed to disable by setting enableGlobalCache: false
in .yarnrc.yml
and re-installing packages so they go into the project's local cache.
Would be nice to have something in the docs about this limitation, I imagine many people's first instinct would be to run their targets from package.json
when setting this up.
pm2 does not seem to be managing properly the startup of 2 instances of an Express server in cluster mode. I'm using yarn PnP for package management (which shouldn't matter, I got the same with npm). My setup is:
node 20.10.0 pm2 5.4.2 yarn 4.5.0
Then to set up a vanilla Express project:
yarn init
"type": "module"
and thestart
target"scripts": { "start": "node index.js" }
inpackage.json
yarn add express
to install express. You should end up with something like this:package.json:
Then for the server (index.js):
Finally, in
ecosystem.config.cjs
:Doing
pm2 start ecosystem.config.cjs
then results in this in~/.pm2/pm2.log
:I tried a couple of alternate ways to start up the cluster, like setting node as the script (providing pnp.cjs and the loader as args), but didn't find anything that works.