nx: WARNING in DefinePlugin Conflicting values for 'process.env.NODE_ENV'

  1. Have installed the latest NX 13.2.2.
  2. Created empty react project.
  3. Created a library with --publishable flag.
  4. Created an empty component inside the library.

When executing command yarn nx run my-project:build got a warning message:

WARNING in DefinePlugin Conflicting values for ‘process.env.NODE_ENV’

I didn’t change any default nx settings during nx installation or when creating the project.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 26
  • Comments: 69 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I updated to 13.9.5 and still get this warning

WARNING in DefinePlugin Conflicting values for 'process.env.NODE_ENV'

Anything else I can do to resolve this?

@jaysoo I think this issue needs to be reopened since #9460 did not fix the issue

Still present in 13.4.3

Update: I found what caused the regression. It was due to another fix we did here #8932.

The PR to fix this has been opened, just getting a round of review and we should include it in 13.10.

I encountered this issue as well, in a project where the NODE_ENV needs to be “testing” for local development, but was always getting set to “development.”

Turns out Webpack’s mode parameter sets process.env.NODE_ENV via DefinePlugin [0]. So, if you use both mode: 'development' and an instance of DefinePlugin, process.env.NODE_ENV can get set with conflicting values…

Another config option I found helpful was setting stats.errorDetails: true [1]. This causes DefinePlugin to print the old and new values to stdout, which was helpful in debugging.

[0] https://webpack.js.org/configuration/mode/ [1] https://webpack.js.org/configuration/stats/#statserrordetails

FYI The error still occurs on out-of-the-box untouched code:

# create something called "app" in the wizard
npx create-nx-workspace --preset=angular

# from storybook readme
yarn add --dev @nrwl/storybook
yarn nx g @nrwl/angular:storybook-configuration app
yarn nx run project-name:storybook       # <-process.env.NODE_ENV warning

Tested today.

this bug is still present in v13.8.4

Add NODE_ENV=production to any .env files such as .env.local solved problem without prefix to scripts.

Done a little more digging and this still happens out of the box using newest versions of @nrwl/*@latest (13.8.7 at time of writing) packages. By this I mean I can create a brand new project and start it and this issue/warning message occurs.

$ npx create-nx-workspace@latest
Need to install the following packages:
  create-nx-workspace@latest
Ok to proceed? (y) y
✔ Workspace name (e.g., org name)     · test-workspace
✔ What to create in the new workspace · react
✔ Application name                    · test-application
✔ Default stylesheet format           · scss
✔ Use Nx Cloud? (It's free and doesn't require registration.) · No

 >  NX   Nx is creating your v13.8.7 workspace.

   To make sure the command works reliably in all environments, and that the preset is applied correctly,
   Nx will run "npm install" several times. Please wait.

✔ Installing dependencies with npm
✔ Nx has successfully created the workspace.

 ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————


 >  NX   First time using Nx? Check out this interactive Nx tutorial.

   https://nx.dev/react-tutorial/01-create-application

   Prefer watching videos? Check out this free Nx course on Egghead.io.
   https://egghead.io/playlists/scale-react-development-with-nx-4038

~/Desktop/tmp$ cd test-workspace/
~/Desktop/tmp/test-workspace [main]$ yarn start
yarn run v1.22.17
$ nx serve

> nx run test-application:serve

<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://localhost:4200/, http://127.0.0.1:4200/
<i> [webpack-dev-server] 404s will fallback to '/index.html'

>  NX  Web Development Server is listening at http://localhost:4200/

Entrypoint main [big] 1.24 MiB = runtime.js 47.4 KiB main.js 1.2 MiB
Entrypoint polyfills [big] 528 KiB = runtime.js 47.4 KiB polyfills.js 480 KiB
Entrypoint styles 219 KiB = runtime.js 47.4 KiB styles.js 172 KiB styles.ef46db3751d8e999.css 0 bytes
chunk (runtime: runtime) main.js (main) 1.19 MiB [initial] [rendered]
chunk (runtime: runtime) polyfills.js (polyfills) 446 KiB [initial] [rendered]
chunk (runtime: runtime) styles.js, styles.ef46db3751d8e999.css (styles) 167 KiB (javascript) 0 bytes (css/mini-extract) [initial] [rendered]
chunk (runtime: runtime) runtime.js (runtime) 31.8 KiB [entry] [rendered]

WARNING in DefinePlugin
Conflicting values for 'process.env.NODE_ENV'

webpack compiled with 1 warning (b9b64df4f912a34d)

So I suspect this is a bug?

this bug is still present in v13.8.5. Is there any workaround for this for now?

Still present in 13.83

@jaysoo Is it possibile reopen the issue after the @prewk clean test?

Hi @msageryd @nemonemi, below is my project.json file. In this file I just add line 38 and update line 44 as suggestion from @cbl980226, no need to define NODE_ENV in .env anymore and it’s work fine. Hope this help!

{
  "root": "apps/rec",
  "sourceRoot": "apps/rec/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nrwl/web:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "compiler": "babel",
        "outputPath": "dist/apps/rec",
        "index": "apps/rec/src/index.html",
        "baseHref": "/",
        "main": "apps/rec/src/main.tsx",
        "polyfills": "apps/rec/src/polyfills.ts",
        "tsConfig": "apps/rec/tsconfig.app.json",
        "assets": ["apps/rec/src/favicon.ico", "apps/rec/src/assets"],
        "styles": [],
        "scripts": [],
        "webpackConfig": "@nrwl/react/plugins/webpack"
      },
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "apps/rec/src/environments/environment.ts",
              "with": "apps/rec/src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "namedChunks": false,
          "extractLicenses": true,
          "vendorChunk": false
        },
        "development": {} // added
      }
    },
    "serve": {
      "executor": "@nrwl/web:dev-server",
      "options": {
        "buildTarget": "rec:build:development", // modified
        "hmr": true
      },
      "configurations": {
        "production": {
          "buildTarget": "rec:build:production",
          "hmr": false
        }
      }
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/rec/**/*.{ts,tsx,js,jsx}"]
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["coverage/apps/rec"],
      "options": {
        "jestConfig": "apps/rec/jest.config.js",
        "passWithNoTests": true
      }
    }
  },
  "tags": []
}

Spent a good chunk of the weekend using git bisect along with the NX tooling (yarn e2e-start-local-registry and yarn e2e-build-package-publish tasks in this repo) to jump between commits between v13.8.3 and v13.8.4 releases. Managed to narrow this issue down to the change made in #8932 .

Not sure what those changes were intended to do or if this behaviour is in fact intended functionality (as I’m new to NX). But:

  • reverting the change made in that PR
  • rebuilding and publishing all NX modules to the local npm registry
  • then installing those changed modules into a fresh nx built react app
  • … and this warning no longer appears.

I hope this helps someone more familiar with NX fix this issue. Thanks all!

EDIT: Looking closer at the changes in that PR - targetConfiguration.defaultConfiguration is production when running the local development server.

I’m also having this issue as of upgrading to 13.8.5

And not only am I getting this warning, I also have my react app running with the production environment. My website was contacting the prod api URL and it took me a while to understand why.

@FloNeu @prewk as far as Storybook is concerned:

This is an issue that appears in the Storybook side. You can check out this reproduction, which is just a pure Angular app (no Nx) with Storybook. The same warning appears. Check out the log here. On Nx, we are using the Storybook builders directly (@storybook/angular:start-storybook). There’s no “middle-person” between your app and Storybook in that case. So all logs are on the Storybook side. You can open an issue on the Storybook repo about that warning!

Thank you all so much!! 😄

@mandarini Repro is out of the box. Yes it’s just a warning, I would put it way down on the priority list 😁

I not sure how you guy test THE FIX that you made, I saw that you already have couple of fix already that it NOT FIX ANYTHING. Have you ever test your fix?

Although, I haven’t tested on version 13.10 just yet.

To me, just removing the defaultConfiguration setting altogether fixed this. Not sure about all the consequences and not sure if this is correct solution, but seems OK so far. The production build is run with explicit --configuration production parameter.

It’s the process.env.NODE_ENV warning, right? It works, but it gives a warning, that’s all, right? Hi, there! Well unfortunately it did not seem to be only a warning for me - the storybook build failed and its dev-server wasn’t started… Made the setup now using nx@14.1.10 - everything was working as expected.

Would love to provide the reproduction - but time is tight right now. But it was just an out-of-the box angular-workspace and setting up storybook for the generated angular-project at nx@latest.

Still getting this on 13.10.1

@msageryd I use your project.json file, then modified at below. After that both command nx serve portal & nx build portal ran successfully.

{
  "root": "apps/portal",
  "sourceRoot": "apps/portal/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nrwl/web:webpack", // change from "@nrwl/web:build"
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "compiler": "babel", // add this
        "outputPath": "dist/apps/portal",
        "index": "apps/portal/src/index.html",
        "baseHref": "/",
        "main": "apps/portal/src/main.js",
        "polyfills": "apps/portal/src/polyfills.js",
        "tsConfig": "apps/portal/tsconfig.app.json",
        "assets": [
          "apps/portal/src/favicon.svg",
          "apps/portal/src/assets",
          {
            "input": "libs/assets/src/lib",
            "glob": "*",
            "output": "assets"
          }
        ],
        "styles": ["apps/portal/src/styles.scss"],
        "scripts": [],
        "webpackConfig": "@nrwl/react/plugins/webpack"
      },
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "apps/portal/src/environments/environment.js",
              "with": "apps/portal/src/environments/environment.prod.js"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "namedChunks": false,
          "extractLicenses": true,
          "vendorChunk": false
        },
        "development": {} // add this
      }
    },
    "serve": {
      "executor": "@nrwl/web:dev-server",
      "options": {
        "buildTarget": "portal:build:development", // change from "portal:build"
        "hmr": true
      },
      "configurations": {
        "production": {
          "buildTarget": "portal:build:production",
          "hmr": false
        }
      }
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/portal/**/*.{ts,tsx,js,jsx}"]
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["coverage/apps/portal"],
      "options": {
        "jestConfig": "apps/portal/jest.config.js",
        "passWithNoTests": true
      }
    }
  },
  "tags": []
}

I guess the warning was introduced by https://github.com/nrwl/nx/pull/7727