Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next.js complains I use a non-standard NODE_ENV even if NODE_ENV is set to a standard value

When I deploy my Next.js project in a Docker linux container, Next.js complains on startup that You are using a non-standard "NODE_ENV" value in your environment. However, the NODE_ENV is set to development, which is a standard value. I have output the value of process.env and NODE_ENV is really set to development.

Here is the code I have written to test the value of process.env from app\api\app\get-env\route.ts

import { NextRequest } from 'next/server';

export async function GET(request: NextRequest) {
    return Response.json(process.env);
}

Here is the output of process.env:

{
    "KUBERNETES_SERVICE_PORT": "443",
    "KUBERNETES_PORT": "tcp://172.18.0.1:443",
    "NODE_VERSION": "21.4.0",
    "HOSTNAME": "headless-ia-7659d5f4c8-z9qbz",
    "YARN_VERSION": "1.22.19",
    "HEADLESS_IA_SERVICE_HOST": "172.18.103.163",
    "HEADLESS_IA_PORT_8080_TCP_ADDR": "172.18.103.163",
    "SHLVL": "1",
    "PORT": "8080",
    "HOME": "/root",
    "HEADLESS_IA_PORT_8080_TCP_PORT": "8080",
    "dev": "dev",
    "HEADLESS_IA_PORT_8080_TCP_PROTO": "tcp",
    "HEADLESS_IA_SERVICE_PORT": "8080",
    "HEADLESS_IA_PORT": "tcp://172.18.103.163:8080",
    "HEADLESS_IA_PORT_8080_TCP": "tcp://172.18.103.163:8080",
    "KUBERNETES_PORT_443_TCP_ADDR": "172.18.0.1",
    "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
    "NEXT_TELEMETRY_DISABLED": "1",
    "KUBERNETES_PORT_443_TCP_PORT": "443",
    "KUBERNETES_PORT_443_TCP_PROTO": "tcp",
    "DEPLOY_STAGE": "dev",
    "KUBERNETES_SERVICE_PORT_HTTPS": "443",
    "KUBERNETES_PORT_443_TCP": "tcp://172.18.0.1:443",
    "KUBERNETES_SERVICE_HOST": "172.18.0.1",
    "PWD": "/src",
    "NODE_ENV": "development",
    "NEXT_RUNTIME": "nodejs",
    "NEXT_DEPLOYMENT_ID": "",
    "__NEXT_OPTIMIZE_FONTS": "true",
    "__NEXT_PRIVATE_RUNTIME_TYPE": ""
}
like image 355
olivierr91 Avatar asked Oct 31 '25 06:10

olivierr91


1 Answers

As you've noticed, Next.js considers the NODE_ENV values development, production and test to be "standard values", and warns if some other value is used.

Even though you are using a standard value, Next.js also warns in the following cases:

  • The environment is development and the commands next start or next build are used
  • The environment is production and the command next dev is used

This can be seen Next.js' source code for the current version (14.0.4 at time of writing), which was added in v12.0.8.

The documentation describes the reasoning behind this:

Setting a non-standard NODE_ENV value may cause dependencies to behave unexpectedly, or worse, break dead code elimination.

You're probably using start or build commands in your deployment. You've used the word "deploy", so I assume that this container is not just a development or testing container, but a production container. In that case, you really should use NODE_ENV=production, as using development may cause some security features of Next.js or other dependencies to be disabled (or in a future version of Next.js or other dependencies), as well as the optimization features referred to in the docs.

like image 179
cbr Avatar answered Nov 01 '25 20:11

cbr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!