Next.js Service Fails on Startup (SIGTERM) - Even Clean Next.js App Affected
b2bspace-ee
HOBBYOP

6 months ago

Next.js Service Fails on Startup (SIGTERM) - Even Clean Next.js App Affected (Project ID: c4eafd4b-5423-4a6f-93c6-a3e9da4a69d9)

Dear Railway Support Team,

We are facing a critical issue with our Next.js services within Project "SEO Performance Analyzer" (Project ID: c4eafd4b-5423-4a6f-93c6-a3e9da4a69d9). The core problem is that Next.js services are crashing with a SIGTERM signal just seconds after their logs indicate they are ready (✓ Ready in ...ms).

Our primary goal is to achieve stable startup for our main Next.js application (service nextjs-frontend, ID: de99147b-4bc9-4306-ac21-d36fb73e50a1 - please verify this ID if it's the old problematic one). However, our diagnostic efforts have revealed a more fundamental issue.

Key Diagnostic Steps Taken & Findings:

  1. Initial Problem: Our main Next.js application (nextjs-frontend) started crashing consistently on startup.

  2. Code Simplification on Main App: We attempted to stabilize it by deploying maximally simplified versions of page.tsx, layout.tsx, and next.config.js, and by correcting middleware.ts. These measures did not consistently resolve the immediate startup crash for the nextjs-frontend service.

  3. Test with a Clean, New Railway Service and Clean Next.js App:

    • We created a brand new Railway service named railway-test (Service ID: 8c22a1c1-d2a9-4773-98b2-cbaef831df04).

    • We deployed a fresh, unmodified Next.js application (from npx create-next-app@latest, Git repo: https://github.com/company-b2bspace/railway-test.git) to this new railway-test service.

    • Initial Result: This clean Next.js app on the new railway-test service ran stably.

  4. Test: Pointing the (Previously Stable) Clean Service to Main Project's Repo (Simplified Code):

    • We then changed the source repository of the stable railway-test service to our main project's repository (company-b2bspace/nextjs-frontend), which contained the aforementioned maximally simplified code.

    • Result: The railway-test service, now deploying our main project's simplified code, also began to crash with SIGTERM.

  5. Critical Finding: Reverting Clean Service to Clean Repo NOW ALSO FAILS:

    • We then reverted the source repository for the railway-test service back to the clean Next.js repository (https://github.com/company-b2bspace/railway-test.git).

    • Current Problem: Now, even this clean, unmodified Next.js application is crashing on the railway-test service (ID: 8c22a1c1-d2a9-4773-98b2-cbaef831df04), which previously ran it stably. It appears the service environment may have been affected by the deployment of our main project's code.

Example crash log for the clean Next.js app on the now-failingrailway-test service (ID: 8c22a1c1-d2a9-4773-98b2-cbaef831df04):

May 26 01:14:48 railway-test > railway-test@0.1.0 start
May 26 01:14:48 railway-test > next start
May 26 01:14:48 railway-test   ▲ Next.js 15.3.2 // Note: This version appears in logs
May 26 01:14:48 railway-test   - Local:        http://localhost:8080
May 26 01:14:48 railway-test ✓ Starting...
May 26 01:14:48 railway-test ✓ Ready in 440ms
May 26 01:14:51 railway-test Stopping Container
May 26 01:14:56 railway-test npm error path /app
... (rest of SIGTERM log) ...

No custom environment variables were set for the clean project deployment on railway-test, and Healthcheck Path was /.

This sequence of events leads us to believe there might be a persistent issue with the service slots or the build/runtime environment provided by Railway for Next.js within our project, possibly triggered or exacerbated by deploying our main application's codebase.

Could you please investigate our Project (ID: c4eafd4b-5423-4a6f-93c6-a3e9da4a69d9) and specifically the railway-test service (ID: 8c22a1c1-d2a9-4773-98b2-cbaef831df04)? We need to understand why a standard Next.js application can become unstable on your platform under these circumstances. Access to more detailed system-level logs would be invaluable.

Thank you for your urgent attention to this matter.

Sincerely, Oleksii Predachenko

Solved$10 Bounty

13 Replies

brody
EMPLOYEE

6 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 6 months ago


opqr
FREE

6 months ago

Please share rest of the SIGTERM log along with a screenshot of your past 1d memory metrics. I think you might be going over your memory limit.


lofimit
HOBBY

6 months ago

Most likely what @opqr said, in case it isn't, please check if the app is listening on the required port and if previous deploys didn't leave corrupted build caches or volumes.
Could also be some version mismatches or incompatible dependencies, but probably not, just my last idea.


b2bspace-ee
HOBBYOP

6 months ago

cleaning storage unit

May 26 00:19:43

seo-vite-react

finished cleaning storage units

May 26 00:41:39

railway-test

Starting Container

May 26 00:41:40

railway-test

npm warn config production Use --omit=dev instead.

May 26 00:41:40

railway-test

May 26 00:41:40

railway-test

> railway-test@0.1.0 start

May 26 00:41:40

railway-test

> next start

May 26 00:41:40

railway-test

May 26 00:41:40

railway-test

▲ Next.js 15.3.2

May 26 00:41:40

railway-test

- Local: http://localhost:8080

May 26 00:41:40

railway-test

- Network: http://10.250.17.212:8080

May 26 00:41:40

railway-test

May 26 00:41:40

railway-test

✓ Starting...

May 26 00:41:40

railway-test

✓ Ready in 371ms

May 26 00:41:44

railway-test

Stopping Container

May 26 00:41:50

railway-test

npm error path /app

May 26 00:41:50

railway-test

npm error command failed

May 26 00:41:50

railway-test

npm error signal SIGTERM

May 26 00:41:50

railway-test

npm error command sh -c next start

May 26 00:41:50

railway-test

npm error A complete log of this run can be found in: /root/.npm/_logs/2025-05-25T19_18_33_612Z-debug-0.log

May 26 01:02:43

railway-test

Starting Container

May 26 01:02:44

railway-test

npm warn config production Use --omit=dev instead.

May 26 01:02:44

railway-test

May 26 01:02:44

railway-test

> railway-test@0.1.0 start

May 26 01:02:44

railway-test

> next start

May 26 01:02:44

railway-test

May 26 01:02:44

railway-test

▲ Next.js 15.3.2

May 26 01:02:44

railway-test

- Local: http://localhost:8080

May 26 01:02:44

railway-test

- Network: http://10.250.16.24:8080

May 26 01:02:44

railway-test

May 26 01:02:44

railway-test

✓ Starting...

May 26 01:02:44

railway-test

✓ Ready in 461ms

May 26 01:02:46

railway-test

Stopping Container

May 26 01:02:50

railway-test

npm error path /app

May 26 01:02:50

railway-test

npm error command failed

May 26 01:02:50

railway-test

npm error signal SIGTERM

May 26 01:02:50

railway-test

npm error command sh -c next start

May 26 01:02:50

railway-test

npm error A complete log of this run can be found in: /root/.npm/_logs/2025-05-25T21_41_39_497Z-debug-0.log

May 26 01:14:47

railway-test

Starting Container

May 26 01:14:48

railway-test

npm warn config production Use --omit=dev instead.

May 26 01:14:48

railway-test

May 26 01:14:48

railway-test

> railway-test@0.1.0 start

May 26 01:14:48

railway-test

> next start

May 26 01:14:48

railway-test

May 26 01:14:48

railway-test

▲ Next.js 15.3.2

May 26 01:14:48

railway-test


smolpaw
HOBBY

6 months ago

Hi, I think I know the problem because i ran into a very similar problem at the start of my current project. Are you using default nixpacks builder used by railway or dockerfile ?
If you are using dockerfile then please post the entire dockerfile so i could have a look at it.

Nextjs by default doesn't do well in a containerized environment as that's not it's default output.
You need to change the output to "standalone" in next config like this and also have a production dockerfile which they highly recommend

```
// next.config.js

module.exports = {

// ... rest of the configuration.

output: "standalone",

};
```


smolpaw

Hi, I think I know the problem because i ran into a very similar problem at the start of my current project. Are you using default nixpacks builder used by railway or dockerfile ?If you are using dockerfile then please post the entire dockerfile so i could have a look at it.Nextjs by default doesn't do well in a containerized environment as that's not it's default output.You need to change the output to "standalone" in next config like this and also have a production dockerfile which they highly recommend```// next.config.jsmodule.exports = {// ... rest of the configuration.output: "standalone",};```

b2bspace-ee
HOBBYOP

6 months ago

Hi, thanks for the suggestions.

Following up on the output: "standalone" advice for Next.js:

I created a brand new, clean Next.js project (npx create-next-app@latest).

In this clean project:

Updated next.config.js to include output: "standalone" and removed experimental.instrumentationHook (as instrumentation.ts is not part of a default clean project).

Updated package.json "start" script to node .next/standalone/server.js.

Ensured dependencies are stable (Next.js 14.2.3, React 18).

Simplified app/layout.js to remove custom fonts (Geist) that caused a build error.

Regenerated package-lock.json after dependency changes.

This correctly configured clean Next.js project (using output: "standalone") was deployed to a newly created service on Railway.

Result: Unfortunately, this clean and correctly configured Next.js project still crashes with SIGTERM a few seconds after the logs show
Ready in ...ms.

Latest crash log for this clean, standalone-configured Next.js app on a new service:

Starting Container

May 27 16:55:56

railway-test

npm warn config production Use --omit=dev instead.

May 27 16:55:56

railway-test

May 27 16:55:56

railway-test

> railway-test@0.1.0 start

May 27 16:55:56

railway-test

> node .next/standalone/server.js

May 27 16:55:56

railway-test

May 27 16:55:56

railway-test

 ▲ Next.js 14.2.3

May 27 16:55:56

railway-test

 - Local:        http://653a19c0a118:8080

May 27 16:55:56

railway-test

 - Network:      http://[fd12:a249:21ad:0:1000:6:7aa4:4bb3]:8080

May 27 16:55:56

railway-test

May 27 16:55:56

railway-test

✓ Starting...

May 27 16:55:56

railway-test

✓ Ready in 54ms

May 27 16:55:59

railway-test

Stopping Container

May 27 16:56:07

railway-test

npm error path /app

May 27 16:56:07

railway-test

npm error command failed

May 27 16:56:07

railway-test

npm error signal SIGTERM

May 27 16:56:07

railway-test

npm error command sh -c next start

May 27 16:56:07

railway-test

npm error A complete log of this run can be found in: /root/.npm/_logs/2025-05-27T12_46_51_739Z-debug-0.log

No custom environment variables were used, and Healthcheck Path was /. Memory usage is minimal before the crash.

Given that a default Next.js application, configured for standalone output as recommended for containerized environments, still fails on a fresh Railway service, this points to an issue beyond typical application code errors.


smolpaw
HOBBY

6 months ago

You didn't answer my other question about build type. are you using nixpacks or dockerfile ?
Can you put this dockerfile and dockerignore at the root of the project ?

https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
https://github.com/vercel/next.js/blob/canary/examples/with-docker/.dockerignore

If your build environment requires environment variables which it shouldn't be since you said it's a clean project, i advise adding them to your service variables and specifying them during builder stage of the dockerfile i gave right before npm run build
Here's more info on it: https://docs.railway.com/guides/dockerfiles#using-variables-at-build-time


smolpaw
HOBBY

6 months ago

Since it is a starter project please put it on github repo and make it public. I will fix it by successfully deploying to railway and open up a pull request with the necessary changes


smolpaw

Since it is a starter project please put it on github repo and make it public. I will fix it by successfully deploying to railway and open up a pull request with the necessary changes

b2bspace-ee
HOBBYOP

6 months ago

Thanks! My clean Next.js test repository is public: https://github.com/company-b2bspace/railway-test

This is a stock create-next-app project where I've configured output: "standalone" in next.config.js, updated the package.json "start" script to node .next/standalone/server.js, set dependencies to Next.js 14.2.3 / React 18, and removed custom fonts from app/layout.js (which were causing a build error).

Looking forward to your PR or any insights.


b2bspace-ee

Thanks! My clean Next.js test repository is public: https://github.com/company-b2bspace/railway-testThis is a stock create-next-app project where I've configured output: "standalone" in next.config.js, updated the package.json "start" script to node .next/standalone/server.js, set dependencies to Next.js 14.2.3 / React 18, and removed custom fonts from app/layout.js (which were causing a build error).Looking forward to your PR or any insights.

smolpaw
HOBBY

6 months ago

Hi, I have opened a pull request with the changes : https://github.com/company-b2bspace/railway-test/pull/1
I was able to successfully deploy the application on railway. You can test it here : https://nextjs-bounty-production.up.railway.app

I have also included a railway config file so you could replicate the same deployment behavior.
The Dockerfile i added is production ready. I wouldn't recommend touching it unless you know how to work with them.


smolpaw

Hi, I have opened a pull request with the changes : https://github.com/company-b2bspace/railway-test/pull/1I was able to successfully deploy the application on railway. You can test it here : https://nextjs-bounty-production.up.railway.appI have also included a railway config file so you could replicate the same deployment behavior.The Dockerfile i added is production ready. I wouldn't recommend touching it unless you know how to work with them.

b2bspace-ee
HOBBYOP

6 months ago

Thank you so much for providing the Dockerfile, .dockerignore, and railway.json examples, and for merging them into my railway-test repository (https://github.com/company-b2bspace/railway-test) via PR #1! I really appreciate you taking the time to set that up.

I've deployed these changes to the railway-test service. The build process now uses the Dockerfile as expected.

Unfortunately, despite these changes and using the Dockerfile build, the clean Next.js application on the railway-test servicestill crashes with a SIGTERM error a few seconds after startup.

Here are the latest logs from the railway-test service after deploying with the Dockerfile:

You reached the start of the range → May 27, 2025 6:56 PM

May 27 19:10:41railway-test Starting Container

May 27 19:10:42railway-test  ▲ Next.js 14.2.3

May 27 19:10:42railway-test - Local:       http://localhost:8080

May 27 19:10:42railway-test - Network:     http://0.0.0.0:8080

May 27 19:10:42railway-test

May 27 19:10:42railway-test ✓ Starting...

May 27 19:10:42railway-test ✓ Ready in 52ms

May 27 19:10:48railway-test Stopping Container

May 27 19:10:57railway-test npm error path /app

May 27 19:10:57railway-test npm error command failed

May 27 19:10:57railway-test npm error signal SIGTERM

May 27 19:10:57railway-test npm error command sh -c node .next/standalone/server.js

May 27 19:10:57railway-test npm error A complete log of this run can be found in: /root/.npm/_logs/2025-05-27T13_55_55_963Z-debug-0.log

It seems the issue might be more deeply rooted in how services are handled or configured within my specific project on Railway, as even a Dockerized clean Next.js app (which should be very stable) is failing.

I've also confirmed that deploying the same clean Next.js app (from the railway-test repo) to Vercel works perfectly fine.

Any further guidance or investigation from the Railway team's side would be greatly appreciated.


b2bspace-ee

Thank you so much for providing the Dockerfile, .dockerignore, and railway.json examples, and for merging them into my railway-test repository (https://github.com/company-b2bspace/railway-test) via PR #1! I really appreciate you taking the time to set that up.I've deployed these changes to the railway-test service. The build process now uses the Dockerfile as expected.Unfortunately, despite these changes and using the Dockerfile build, the clean Next.js application on the railway-test servicestill crashes with a SIGTERM error a few seconds after startup.Here are the latest logs from the railway-test service after deploying with the Dockerfile:You reached the start of the range → May 27, 2025 6:56 PMMay 27 19:10:41railway-test Starting ContainerMay 27 19:10:42railway-test  ▲ Next.js 14.2.3May 27 19:10:42railway-test - Local:       http://localhost:8080May 27 19:10:42railway-test - Network:     http://0.0.0.0:8080May 27 19:10:42railway-testMay 27 19:10:42railway-test ✓ Starting...May 27 19:10:42railway-test ✓ Ready in 52msMay 27 19:10:48railway-test Stopping ContainerMay 27 19:10:57railway-test npm error path /appMay 27 19:10:57railway-test npm error command failedMay 27 19:10:57railway-test npm error signal SIGTERMMay 27 19:10:57railway-test npm error command sh -c node .next/standalone/server.jsMay 27 19:10:57railway-test npm error A complete log of this run can be found in: /root/.npm/_logs/2025-05-27T13_55_55_963Z-debug-0.logIt seems the issue might be more deeply rooted in how services are handled or configured within my specific project on Railway, as even a Dockerized clean Next.js app (which should be very stable) is failing.I've also confirmed that deploying the same clean Next.js app (from the railway-test repo) to Vercel works perfectly fine.Any further guidance or investigation from the Railway team's side would be greatly appreciated.

smolpaw
HOBBY

6 months ago

The log you posted is wrong.

One of the log line you posted says "node .next/standalone/server.js"

This is incorrect. It should say "node server.js" for my dockerfile deployment.

.next/standalone/server.js was the previous command you used before my pr

I recommend deleting the service and redeploying again.

Also to check logs for a service go to Deployments -> View Logs -> Deploy Logs

If you are checking the logs in Observability tab then you are likely looking at old logs.


smolpaw
HOBBY

6 months ago

Also do not change the start command. leave it empty.


smolpaw

The log you posted is wrong.One of the log line you posted says "node .next/standalone/server.js"This is incorrect. It should say "node server.js" for my dockerfile deployment..next/standalone/server.js was the previous command you used before my prI recommend deleting the service and redeploying again.Also to check logs for a service go to Deployments -> View Logs -> Deploy LogsIf you are checking the logs in Observability tab then you are likely looking at old logs.

b2bspace-ee
HOBBYOP

6 months ago

Thank you @smolpaw so much for your help!

After deleting the old problematic railway-test service and creating a brand new service on Railway, I deployed the clean Next.js project from https://github.com/company-b2bspace/railway-test (which includes your Dockerfile setup from PR #1).

Starting Container

May 27 20:39:52 railway-test-2 ▲ Next.js 14.2.3

May 27 20:39:52 railway-test-2 - Local: http://localhost:8080

May 27 20:39:52 railway-test-2 - Network: http://0.0.0.0:8080

May 27 20:39:52 railway-test-2

May 27 20:39:52 railway-test-2 ✓ Starting...

May 27 20:39:52 railway-test-2 ✓ Ready in 52ms


Status changed to Solved chandrika 6 months ago


Loading...