appsmithorg/appsmith · critical · Error

The NODE_ENV environment variable is required but was not sp

Error message

The NODE_ENV environment variable is required but was not specified.

What it means

Thrown by Appsmith's client build config (a Create React App fork) in config/env.js. The build pipeline reads process.env.NODE_ENV to decide which .env file set to load and which webpack mode to run. Because every downstream decision (dev vs prod optimizations, .env.local inclusion, minification) depends on it, env.js refuses to boot without an explicit value. It is a hard precondition gate before any webpack config is assembled.

Source

Thrown at app/client/config/env.js:12

"use strict";

const fs = require("fs");
const path = require("path");
const paths = require("./paths");

// Make sure that including paths.js after env.js will read .env variables.
delete require.cache[require.resolve("./paths")];

const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV) {
  throw new Error(
    "The NODE_ENV environment variable is required but was not specified.",
  );
}

// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
const dotenvFiles = [
  `${paths.dotenv}.${NODE_ENV}.local`,
  // Don't include `.env.local` for `test` environment
  // since normally you expect tests to produce the same
  // results for everyone
  NODE_ENV !== "test" && `${paths.dotenv}.local`,
  `${paths.dotenv}.${NODE_ENV}`,
  paths.dotenv,
].filter(Boolean);

// Load environment variables from .env* files. Suppress warnings using silent
// if this file is missing. dotenv will never modify any environment variables
// that have already been set.  Variable expansion is supported in .env files.

View on GitHub (pinned to 8cd9021c24)

Solutions

  1. Set NODE_ENV explicitly before the build command, e.g. run scripts via react-scripts (which sets it) or prefix with 'NODE_ENV=production' / 'cross-env NODE_ENV=development'.
  2. If running inside Docker, add ENV NODE_ENV=production to the Dockerfile or pass -e NODE_ENV=production to docker run.
  3. In CI, export NODE_ENV in the job step before the npm script executes.
  4. Avoid requiring config/env.js from custom Node scripts; use react-scripts entry points which set NODE_ENV for you.

Example fix

// before
$ node config/env.js
// Error: The NODE_ENV environment variable is required...

// after
$ NODE_ENV=production node config/env.js
// or, in package.json scripts, use the CRA wrapper which injects it:
//   "build": "react-scripts build"
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.NODE_ENV) {
  throw new Error('Set NODE_ENV before running the build (development|production|test).');
}

Type guard

const isNodeEnv = (v: string | undefined): v is 'development'|'production'|'test' =>
  v === 'development' || v === 'production' || v === 'test';

Prevention

When it happens

Trigger: Running a react-scripts-based script (start/build/test) in a context where NODE_ENV is unset: a raw 'node config/env.js', a CI runner that does not export NODE_ENV, a Docker image started with an empty env, or a custom npm script that calls the webpack config directly instead of going through react-scripts which normally injects NODE_ENV.

Common situations: CI pipelines that invoke the build without 'cross-env NODE_ENV=production'; Docker containers that drop the env var; IDE run configurations that spawn node directly; upgrading react-scripts where the injected NODE_ENV contract changed; shell sessions where NODE_ENV was never exported.

Related errors


AI-assisted analysis of appsmithorg/appsmith@8cd9021c24 (2026-08-12). Data as JSON: /api/errors/79dd09fc284ee0c4. Report an issue: GitHub.