next.js v16 fails to deploy due to node v18
kynnyhsap
PROOP

7 months ago

trying to deploy next.js v16 but deployment fails due to node version

next.js v16 now requires node c20+ (https://nextjs.org/blog/next-16#breaking-changes-and-other-updates) , and i even set RAILPACK_NODE_VERSION env to 22 but it still thinks i am using node 18 for some reason =(

$10 Bounty

3 Replies

Railway
BOT

7 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


sarahkb125
EMPLOYEE

7 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 sarahkb125 7 months ago


sumon9836
FREE

7 months ago

Next.js version 16 now requires Node.js version 20 or higher to build and run. Railway currently uses Node 18 by default, which causes the deployment to fail.

Below is the complete solution to fix the problem:

1. Update the Node version in package.json

Open the package.json file and add the following section if it’s not already there:

"engines": {

"node": "22.x"

}

This tells Railway to use Node.js version 22 for the build process.

2. Add an .nvmrc file

In the root of the project (same place as package.json), create a file named .nvmrc and add:

22

This helps both locally and during deployment to ensure Node.js 22 is used.

3. Set the environment variable on Railway

In the Railway dashboard:

Go to the project service

Open the “Variables” tab

Add a new variable:

RAILWAY_NODE_VERSION = 22

Alternatively, you can use:

NODE_VERSION = 22

Do not use RAILPACK_NODE_VERSION — it is not a valid variable.

4. Clear build cache and redeploy

Railway sometimes caches previous builds that used Node 18. To fix this:

Go to the “Deployments” section in Railway

Click “Clear cache & redeploy”

Or, make a small change in your project (for example, update the README file), commit it, and push again. This will trigger a fresh deployment.

5. Verify build logs

After redeploying, open the build logs in Railway and confirm that it says:

Using Node.js version: 22.x

If it still shows Node 18, double-check the package.json, .nvmrc, and environment variable settings.

After completing these steps, the Next.js 16 project will build and deploy successfully on Railway using Node.js 22.


sumon9836

Next.js version 16 now requires Node.js version 20 or higher to build and run. Railway currently uses Node 18 by default, which causes the deployment to fail. Below is the complete solution to fix the problem: 1\. Update the Node version in package.json Open the package.json file and add the following section if it’s not already there: "engines": { "node": "22.x" } This tells Railway to use Node.js version 22 for the build process. 2\. Add an .nvmrc file In the root of the project (same place as package.json), create a file named .nvmrc and add: 22 This helps both locally and during deployment to ensure Node.js 22 is used. 3\. Set the environment variable on Railway In the Railway dashboard: Go to the project service Open the “Variables” tab Add a new variable: RAILWAY\_NODE\_VERSION = 22 Alternatively, you can use: NODE\_VERSION = 22 Do not use RAILPACK\_NODE\_VERSION — it is not a valid variable. 4\. Clear build cache and redeploy Railway sometimes caches previous builds that used Node 18\. To fix this: Go to the “Deployments” section in Railway Click “Clear cache & redeploy” Or, make a small change in your project (for example, update the README file), commit it, and push again. This will trigger a fresh deployment. 5\. Verify build logs After redeploying, open the build logs in Railway and confirm that it says: Using Node.js version: 22.x If it still shows Node 18, double-check the package.json, .nvmrc, and environment variable settings. After completing these steps, the Next.js 16 project will build and deploy successfully on Railway using Node.js 22.

6 months ago

Thank you!


Welcome!

Sign in to your Railway account to join the conversation.

Loading...