I have tried to set up a cluster by PM2 on Next JS app on Azure App Service (Linux) using startup command "pm2-runtime start ecosystem.config.js" or "pm2 --no-daemon start ecosystem.config.js". Both commands fail. When I am using pm2-runtime the current working directory passed to NodeJS script becomes: "wwwroot/ecosystem.config.js/.next" as a "directory parameters" and the server fails. In second command pm2 --no-daemon I receive information Unknown or unexpected option: --no-daemon. Both commands work for "fork" mode. Is it possible to set up a cluster mode for the azure app service with nextjs app?
ecosystem.config.code
module.exports = {
apps: [
{
name: 'next',
script: './node_modules/next/dist/bin/next',
args: 'start -p ' + (process.env.PORT || 3000),
instances: 2,
exec_mode: 'cluster',
watch: false,
autorestart: true,
},
],
};*
Errors for --no-daemon
Error for pm2-runtime
Error: Could not find a production build in the '/home/site/wwwroot/ecosystem.config.js/.next' directory. Try building your app with 'next build' before starting the production se
rver. https://err.sh/vercel/next.js/production-start-no-build-id
0|next| at Server.readBuildId (/home/site/wwwroot/node_modules/next/next-server/server/next-server.ts:2044:15)
0|next| | at new Server (/home/site/wwwroot/node_modules/next/next-server/server/next-server.ts:199:25)
0|next| | at createServer (/home/site/wwwroot/node_modules/next/server/next.ts:41:10)
0|next| | at start (/home/site/wwwroot/node_modules/next/server/lib/start-server.ts:9:15)
0|next| | at exec (/home/site/wwwroot/node_modules/next/cli/next-start.ts:53:3)
0|next| | at /home/site/wwwroot/node_modules/next/bin/next.ts:113:19 code here