DEV Community

ac1dr41n
ac1dr41n

Posted on

How to set Next.js cwd when starting

I'm trying to start a node application that uses next.js. I'm using PM2 as a process manager. I have the pm2 ecosystem.config.js file set with "cwd" to a specific path, like this:

apps: [
{
name: "fe",
script: "npm",
cwd: "/path/to/app/current",
args: "start",
instances: 4,
exec_mode: "cluster",
}
]
};

In this set up, "current" is a soft link to a directory that is the commit hash of the current deployment (capistrano-style deployments).

When I start the application using PM2, it seems that next.js fails to start. It seems to be looking in the wrong directory. Specifically, its looking in "/path/to/app" instead of "/path/to/app/current". Next.js always fails to start with Exit 1.

0|fe | npm ERR! code ELIFECYCLE
0|fe | npm ERR! errno 1
0|fe | npm ERR! vf-app-name@0.1.0 start:
next start
0|fe | npm ERR! Exit status 1
0|fe | npm ERR!
0|fe | npm ERR! Failed at the vf-app-name@0.1.0 start script.
0|fe | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

In another log file, I see:

1|fe | > vf-app-name@0.1.0 start /path/to/app/a15f0a31c2457e42721d675880b36bab75bcc74c
1|fe | > next start

You can see its not including the "current" path.

I can't seem to find where this needs to be set? I set it in ecosystem.config.js. Where else does it need to be set?

Thanks in advance!

Top comments (0)