Receiving an error when attempting to start node (next.js) app via yarn and pm2. My google fu didn't turn up anything useful. I suspect the issue is with nvm, though I don't have enough experience to understand how to fix it.
Ubuntu 20.04
nvm 0.38.0
node v14.5.0
yarn 1.22.10
pm2 4.5.6
ecosystem.config.js
module.exports = {
apps: [
{
name: "next",
script: "yarn",
interpreter: "bash",
args: "start:next",
instances: 1,
env: {
NODE_ENV: "development",
},
env_staging: {
NODE_ENV: "production",
},
env_production: {
NODE_ENV: "production",
}
}
]
}
Starting file via:
pm2 start ecosystem.config.js --env staging
or
pm2 start yarn --interpreter bash --name next -- start:next
Receiving errors:
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/home/deploy/.pm2/pm2.log last 15 lines:
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] online
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] exited with code [2] via signal [SIGINT]
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] starting in -fork mode-
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] online
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] exited with code [2] via signal [SIGINT]
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] starting in -fork mode-
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] online
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] exited with code [2] via signal [SIGINT]
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] starting in -fork mode-
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] online
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] exited with code [2] via signal [SIGINT]
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] starting in -fork mode-
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] online
PM2 | 2021-04-08T18:33:28: PM2 log: App [express:0] exited with code [2] via signal [SIGINT]
PM2 | 2021-04-08T18:33:28: PM2 log: Script /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn had too many unstable restarts (16). Stopped. "errored"
/home/deploy/.pm2/logs/express-out.log last 15 lines:
/home/deploy/.pm2/logs/express-error.log last 15 lines:
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 3: /bin: Is a directory
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 4: /bin: Is a directory
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 5: use strict: command not found
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 7: var: command not found
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 8: syntax error near unexpected token `('
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 8: `var majorVer = parseInt(ver.split('.')[0], 10);'
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 3: /bin: Is a directory
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 4: /bin: Is a directory
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 5: use strict: command not found
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 7: var: command not found
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 8: syntax error near unexpected token `('
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 8: `var majorVer = parseInt(ver.split('.')[0], 10);'
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 3: /bin: Is a directory
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 4: /bin: Is a directory
0|express | /home/deploy/.nvm/versions/node/v14.5.0/bin/yarn: line 5: use strict: command not found
start:next
runsnext start
. If Iyarn start:next
in project dir, it runs fine. The command to start an app via yarn in pm2, you'd usepm2 start yarn --interpreter bash --name appname -- start
, replacing start with whatever script defined in package.json. Within the ecosystem file I'm essentially doing the same thing as far as I can tell. – Perkpm2 start yarn --interpreter bash --name appname -- start:next
fails with the same errors above. – Perk