Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gsbelarus opened this issue Nov 28, 2021 · 69 comments · Fixed by #9460 or #9656
Closed

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

gsbelarus opened this issue Nov 28, 2021 · 69 comments · Fixed by #9460 or #9656
Assignees
Labels
outdated scope: react Issues related to React support for Nx type: bug

Comments

@gsbelarus
Copy link

  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.

@puku0x
Copy link
Contributor

puku0x commented Nov 29, 2021

I guess the warning was introduced by #7727

@davidslaby
Copy link
Contributor

I have the same issue after migration to the latest version 13.2.3.

@AgentEnder AgentEnder added the scope: react Issues related to React support for Nx label Dec 7, 2021
@kevinlandsberg
Copy link

kevinlandsberg commented Dec 10, 2021

I have the same issue with NX@13.3.0!

WARNING in DefinePlugin
Conflicting values for 'process.env.NODE_ENV'
Screenshot 2021-12-10 at 11 36 08

@davidslaby
Copy link
Contributor

NX@13.3.1 still the same issue.

@gsbelarus
Copy link
Author

Still present in 13.4.3

@vincent-thomas
Copy link

I got this issue with a react app. I don't know how to fix it!

@virus2016
Copy link

Same

@dannysellers
Copy link

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

@rjaguilar
Copy link

Still present in 13.83

@Fangxin920915
Copy link

DefinePlugin
Conflicting values for 'process.env'

warning

DefinePlugin

大家有没有办法呀

@mondo192
Copy link

mondo192 commented Mar 5, 2022

this bug is still present in v13.8.4

@phaniteja1
Copy link

phaniteja1 commented Mar 8, 2022

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

@cristian-aldea
Copy link

cristian-aldea commented Mar 9, 2022

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.

@rhiadj
Copy link

rhiadj commented Mar 9, 2022

Same issue as others in 13.8.4 and 13.8.5

Workarounds suggested here worked for me: #9241 (comment)

Feels like a regression given no code changes give different results between versions.

Thanks.

@rhiadj
Copy link

rhiadj commented Mar 11, 2022

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?

@rhiadj
Copy link

rhiadj commented Mar 13, 2022

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.

@RayOconnor
Copy link

RayOconnor commented Mar 13, 2022

Just piling on. I run into this bug after using create Reach App and immediately trying to install and run storybook.

yarn create react-app my-app
cd my-app
npx sb init
yarn storybook

debugging:

➜  my-app git:(main) ✗ yarn storybook
yarn run v1.22.17
$ start-storybook -p 6006 -s public
info @storybook/react v6.4.19
info 
(node:35924) DeprecationWarning: --static-dir CLI flag is deprecated, see:

https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated---static-dir-cli-flag
(Use `node --trace-deprecation ...` to show where the warning was created)
info => Loading presets
info => Serving static files from ./public at /
info => Loading Webpack configuration from `node_modules/react-scripts`
info => Removing existing JavaScript and TypeScript rules.
info => Modifying Create React App rules.
info => Using default Webpack5 setup
<i> [webpack-dev-middleware] wait until bundle finished
10% building 0/18 entries 2/18 dependencies 0/2 modules
info => Ignoring cached manager due to change in manager config
<i> [webpack-dev-middleware] wait until bundle finished
69% building finish ReactRefreshPluginassets by chunk 5.18 MiB (id hint: vendors)
  assets by status 4.79 MiB [big]
    asset vendors-node_modules_storybook_addon-actions_dist_esm_register_js-node_modules_storybook_addo-ca05bf.manager.bundle.js 4.43 MiB [emitted] [big] (id hint: vendors)
    asset vendors-node_modules_storybook_components_dist_esm_ScrollArea_OverlayScrollbars_js.manager.bundle.js 372 KiB [emitted] [big] (id hint: vendors)
  asset vendors-node_modules_storybook_components_dist_esm_syntaxhighlighter_syntaxhighlighter_js.manager.bundle.js 197 KiB [emitted] (id hint: vendors)
  asset vendors-node_modules_storybook_components_dist_esm_tooltip_WithTooltip_js.manager.bundle.js 115 KiB [emitted] (id hint: vendors)
  asset vendors-node_modules_storybook_components_dist_esm_controls_Color_js.manager.bundle.js 71 KiB [emitted] (id hint: vendors)
  asset vendors-node_modules_storybook_components_dist_esm_ScrollArea_GlobalScrollAreaStyles_js.manager.bundle.js 15.6 KiB [emitted] (id hint: vendors)
asset runtime~main.manager.bundle.js 14.1 KiB [emitted] (name: runtime~main)
asset index.html 3.77 KiB [emitted]
asset main.manager.bundle.js 1.6 KiB [emitted] (name: main)
asset node_modules_unfetch_dist_unfetch_js.manager.bundle.js 1.27 KiB [emitted]
Entrypoint main [big] 4.44 MiB = runtime~main.manager.bundle.js 14.1 KiB vendors-node_modules_storybook_addon-actions_dist_esm_register_js-node_modules_storybook_addo-ca05bf.manager.bundle.js 4.43 MiB main.manager.bundle.js 1.6 KiB
orphan modules 1.59 MiB [orphan] 335 modules
runtime modules 8.67 KiB 14 modules
javascript modules 4.61 MiB 918 modules
json modules 1.52 KiB
  ./node_modules/character-entities-legacy/index.json 1.24 KiB [built] [code generated]
  ./node_modules/character-reference-invalid/index.json 289 bytes [built] [code generated]

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

1 WARNING in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)

1 warning has detailed information that is not shown.
Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.

manager (webpack 5.70.0) compiled with 2 warnings in 8683 ms
99% done plugins webpack-hot-middlewarewebpack built preview 0fdf89cf50b056bf7f85 in 11133ms
ModuleBuildError: Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] /Users/raoconnor/Personal/my-app/src/stories/Button.stories.jsx: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: "local yarn dev". (While processing: "/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/index.js")
    at module.exports (/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/create.js:58:11)
    at module.exports (/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/index.js:19:10)
    at async (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:44:33)
    at async (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:186:15)
    at /Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:216:13
    at Generator.next (<anonymous>)
    at /Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/config/full.js:229:21
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:25:3)
    at Generator.next (<anonymous>)
    at step (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:269:25)
    at evaluateAsync (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:291:5)
    at Function.errback (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:113:7)
    at errback (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:72:18)
    at async (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:188:31)
    at onFirstPause (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:216:13)
    at processResult (/Users/raoconnor/Personal/my-app/node_modules/webpack/lib/NormalModule.js:758:19)
    at /Users/raoconnor/Personal/my-app/node_modules/webpack/lib/NormalModule.js:860:5
    at /Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:399:11
    at /Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:251:18
    at context.callback (/Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /Users/raoconnor/Personal/my-app/node_modules/babel-loader/lib/index.js:59:103
ModuleBuildError: Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] /Users/raoconnor/Personal/my-app/src/stories/Header.stories.jsx: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: "local yarn dev". (While processing: "/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/index.js")
    at module.exports (/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/create.js:58:11)
    at module.exports (/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/index.js:19:10)
    at async (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:44:33)
    at async (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:186:15)
    at /Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:216:13
    at Generator.next (<anonymous>)
    at /Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/config/full.js:229:21
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:25:3)
    at Generator.next (<anonymous>)
    at step (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:269:25)
    at evaluateAsync (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:291:5)
    at Function.errback (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:113:7)
    at errback (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:72:18)
    at async (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:188:31)
    at onFirstPause (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:216:13)
    at processResult (/Users/raoconnor/Personal/my-app/node_modules/webpack/lib/NormalModule.js:758:19)
    at /Users/raoconnor/Personal/my-app/node_modules/webpack/lib/NormalModule.js:860:5
    at /Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:399:11
    at /Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:251:18
    at context.callback (/Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /Users/raoconnor/Personal/my-app/node_modules/babel-loader/lib/index.js:59:103
ModuleBuildError: Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] /Users/raoconnor/Personal/my-app/src/stories/Page.stories.jsx: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: "local yarn dev". (While processing: "/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/index.js")
    at module.exports (/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/create.js:58:11)
    at module.exports (/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/index.js:19:10)
    at async (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:44:33)
    at async (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:186:15)
    at /Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:216:13
    at Generator.next (<anonymous>)
    at /Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/config/full.js:229:21
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:25:3)
    at Generator.next (<anonymous>)
    at step (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:269:25)
    at evaluateAsync (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:291:5)
    at Function.errback (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:113:7)
    at errback (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:72:18)
    at async (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:188:31)
    at onFirstPause (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:216:13)
    at processResult (/Users/raoconnor/Personal/my-app/node_modules/webpack/lib/NormalModule.js:758:19)
    at /Users/raoconnor/Personal/my-app/node_modules/webpack/lib/NormalModule.js:860:5
    at /Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:399:11
    at /Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:251:18
    at context.callback (/Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /Users/raoconnor/Personal/my-app/node_modules/babel-loader/lib/index.js:59:103
ModuleBuildError: Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] /Users/raoconnor/Personal/my-app/.storybook/preview.js-generated-config-entry.js: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: "local yarn dev". (While processing: "/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/index.js")
    at module.exports (/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/create.js:58:11)
    at module.exports (/Users/raoconnor/Personal/my-app/node_modules/babel-preset-react-app/index.js:19:10)
    at async (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:44:33)
    at async (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:186:15)
    at /Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:216:13
    at Generator.next (<anonymous>)
    at /Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/config/full.js:229:21
    at Generator.next (<anonymous>)
    at Function.<anonymous> (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:25:3)
    at Generator.next (<anonymous>)
    at step (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:269:25)
    at evaluateAsync (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:291:5)
    at Function.errback (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:113:7)
    at errback (/Users/raoconnor/Personal/my-app/node_modules/@babel/core/lib/gensync-utils/async.js:72:18)
    at async (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:188:31)
    at onFirstPause (/Users/raoconnor/Personal/my-app/node_modules/gensync/index.js:216:13)
    at processResult (/Users/raoconnor/Personal/my-app/node_modules/webpack/lib/NormalModule.js:758:19)
    at /Users/raoconnor/Personal/my-app/node_modules/webpack/lib/NormalModule.js:860:5
    at /Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:399:11
    at /Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:251:18
    at context.callback (/Users/raoconnor/Personal/my-app/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
    at /Users/raoconnor/Personal/my-app/node_modules/babel-loader/lib/index.js:59:103

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@jeneser
Copy link

jeneser commented Mar 14, 2022

Now we can pass the env vars before passing the command. environment-variables

NODE_ENV=development nx build app-xxx --skip-nx-cache --verbose 

@RayOconnor
Copy link

@jeneser confirmed that modifying package.json to include your suggestion fixes the error:
"storybook": "NODE_ENV=development start-storybook -p 6006 -s public",

In context:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "storybook": "NODE_ENV=development start-storybook -p 6006 -s public",
    "build-storybook": "build-storybook -s public"
  },

@tammai-bigin
Copy link

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

@cbl980226
Copy link
Contributor

cbl980226 commented Mar 18, 2022

React Project Configuration

project.json

{
  "root": "apps/react",
  "sourceRoot": "apps/react/src",
  "projectType": "application",
  // leave out ......
  "targets": {
    "build": {
      "executor": "@nrwl/web:webpack",
      "outputs": [
        "{options.outputPath}"
      ],
      "defaultConfiguration": "production",
      "options": {
        // leave out ......
      },
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "apps/app-react/src/environments/environment.ts",
              "with": "apps/app-react/src/environments/environment.prod.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "namedChunks": false,
          "extractLicenses": true,
          "vendorChunk": false
        },
        // add (can be ignored, because this is default)
        "development": {
          "fileReplacements": [],
          "optimization": false,
          "outputHashing": "all",
          "sourceMap": true,
          "namedChunks": false,
          "extractLicenses": false,
          "vendorChunk": false
        }
      }
    },
    "serve": {
      "executor": "@nrwl/web:dev-server",
      "options": {
        // try changing
        // "buildTarget": "app-react:build"
        // to
        "buildTarget": "app-react:build:development",
        "hmr": true
      },
      "configurations": {
        "production": {
          "buildTarget": "app-react:build:production",
          "hmr": false
        }
      }
    }
  }
}

@nemonemi
Copy link

nemonemi commented Mar 21, 2022

I have tried applying the configuration adjustments, and I've managed to fix it for the build, but not the serve command.

λ set NODE_ENV=development && nx serve bd-application--verbose

> nx run bd-application:serve --verbose

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

>  NX  Web Development Server is listening at http://localhost:4203/bd/application/management

Entrypoint main [big] 6.33 MiB (8.24 MiB) = runtime.js 49.5 KiB main.js 6.28 MiB 3 auxiliary assets
Entrypoint polyfills [big] 480 KiB (577 KiB) = runtime.js 49.5 KiB polyfills.js 431 KiB 2 auxiliary assets
chunk (runtime: runtime) main.js (main) 5.99 MiB (javascript) 148 KiB (asset) [initial] [rendered]
chunk (runtime: runtime) polyfills.js (polyfills) 397 KiB [initial] [rendered]
chunk (runtime: runtime) runtime.js (runtime) 33.3 KiB [entry] [rendered]

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

webpack compiled with 1 warning (b82e2e087893d6f4)
{
  "root": "apps/bd/application",
  "sourceRoot": "apps/bd/application/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nrwl/web:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "development",
      "options": {
        ...
      },
      "configurations": {
        "development": {
          ...
        },
        "production": {
          ...
        }
      }
    },
    "serve": {
      "executor": "@nrwl/web:dev-server",
      "options": {
        "buildTarget": "bd-application:build:development",
        "port": 4203,
        "hmr": true
      }
    },
    ...
  }
  ...
}
 Node : 16.14.0
   OS   : win32 x64
   yarn : 3.0.2

   nx : 13.9.2
   @nrwl/angular : undefined
   @nrwl/cypress : 13.9.2
   @nrwl/detox : undefined
   @nrwl/devkit : 13.9.2
   @nrwl/eslint-plugin-nx : 13.9.2
   @nrwl/express : undefined
   @nrwl/jest : 13.9.2
   @nrwl/js : 13.9.2
   @nrwl/linter : 13.9.2
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : undefined
   @nrwl/nx-cloud : undefined
   @nrwl/nx-plugin : undefined
   @nrwl/react : 13.9.2
   @nrwl/react-native : undefined
   @nrwl/schematics : 8.12.11
   @nrwl/storybook : 13.9.2
   @nrwl/web : 13.9.2
   @nrwl/workspace : 13.9.2
   typescript : 4.3.5
   rxjs : 6.6.7

@msageryd
Copy link

This seems quite fragile. I discovered that my production build was actually a dev-build:

image

I tried everything suggested in this thread without success. In an attempt to just make my .env.production file count as touched I changed NODE_ENV=production to NODE_ENV=production_.

After this change I got rid of the "Conflicting values" warning and the site is buildt in production mode. This is 100% reproducible. What is going on here?

When I use production_ with an empty line above and no newline after the site builds as production.
image

If I move NODE_ENV=production_ elsewhere in .env.production, the problem returns.
If I add a new line after NODE_ENV=production_ the problem returns.
If there is not an empty line above NODE_ENV=production_ the problem returns.

The parsing of .env files seeme very sketchy to me.

@tammai-bigin
Copy link

tammai-bigin commented Mar 21, 2022

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": []
}

@jaysoo
Copy link
Member

jaysoo commented Apr 1, 2022

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.

jaysoo added a commit to jaysoo/nx that referenced this issue Apr 1, 2022
jaysoo added a commit to jaysoo/nx that referenced this issue Apr 1, 2022
jaysoo added a commit to jaysoo/nx that referenced this issue Apr 1, 2022
jaysoo added a commit to jaysoo/nx that referenced this issue Apr 1, 2022
jaysoo added a commit to jaysoo/nx that referenced this issue Apr 1, 2022
sidmonta pushed a commit to sidmonta/nx that referenced this issue Apr 2, 2022
…d webpack Plugins (DefinePlugin) (nrwl#9460)

ISSUES CLOSED: nrwl#7924

Co-authored-by: Nicholas Cunningham <ndcunningham>
sidmonta pushed a commit to sidmonta/nx that referenced this issue Apr 2, 2022
@enchorb
Copy link

enchorb commented Apr 9, 2022

Still getting this on 13.10.1

@nemonemi
Copy link

nemonemi commented Apr 11, 2022

I am seeing this issue when I misconfigure my NODE_ENV and the build configuration, otherwise, I am not seeing the error - 13.9.2

I am also now explicit with the configuration:

When I wanna test something else aside from the local "development" I simply set, in windows:

set NODE_ENV=production&&yarn dlx nx serve --configuration=qas bd

"targets": {
    "build": {
      "executor": "@nrwl/web:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
         ...
       },
      "configurations": {
        "development": {
          "optimization": false,
          "outputHashing": "all",
          "sourceMap": true,
          "extractCss": true,
          "namedChunks": true,
          "vendorChunk": false,
          "assets": [
            "apps/bd/src/favicon.ico",
            "apps/bd/src/assets",
            "apps/bd/src/mockServiceWorker.js",
            
          ]
        },
        "qas": {
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": true,
          "extractCss": true,
          "namedChunks": false,
          "extractLicenses": true,
          "vendorChunk": false,
          "assets": ["apps/bd/src/favicon.ico", "apps/bd/src/assets"]
        },
        "production": {
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "extractLicenses": true,
          "vendorChunk": false,
          "assets": ["apps/bd/src/favicon.ico", "apps/bd/src/assets"],
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "2mb",
              "maximumError": "5mb"
            }
          ]
        }
      }
    },
    "serve": {
      "executor": "@nrwl/web:dev-server",
      "options": {
        "buildTarget": "bd:build:development",
        "port": 4203,
        "hmr": true
      },
      "configurations": {
        "qas": {
          "buildTarget": "bd:build:qas",
          "hmr": false
        },
        "production": {
          "buildTarget": "bd:build:production",
          "hmr": false
        }
      }
    },

sdg9 added a commit to caribou-crew/mezzo that referenced this issue Apr 12, 2022
@kamontat
Copy link

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.

@jaysoo
Copy link
Member

jaysoo commented Apr 21, 2022

If you're still running into this issue in 13.10 or 14.0, please make sure that:

  1. You don't manually set NODE_ENV to something else that doesn't match the configuration.
  2. You have both the development and production configurations for your project's build target.

If you're unsure try creating a new Nx 14 workspace and compare the generated configuration.

For example,

npx create-nx-workspace@latest test --preset=react --appName=demo

# Then build
nx build demo

There should be no warnings on conflicting process.envNODE_ENV values.

If you run into any more problems, please link a reproduction so we can investigate. This issue remains resolved as far as I'm aware.

@prewk
Copy link

prewk commented May 30, 2022

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.

@avol-io
Copy link

avol-io commented Jul 4, 2022

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

@FloNeu
Copy link

FloNeu commented Jul 15, 2022

I just wanted to setup an angular app with nx-workspace and have the exact issue when running storybook!

@mandarini
Copy link
Member

@FloNeu can you please share a reproduction repository, so that I can manage to reproduce your issue and help you?

@mandarini
Copy link
Member

It's the process.env.NODE_ENV warning, right? It works, but it gives a warning, that's all, right?

@prewk
Copy link

prewk commented Jul 20, 2022

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

@FloNeu
Copy link

FloNeu commented Jul 21, 2022

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.

@mandarini
Copy link
Member

@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!! :D

@prewk
Copy link

prewk commented Jul 21, 2022

Oh I see, sorry for wasting your time on this!

@mandarini
Copy link
Member

Oh no worries at all @prewk !!! It's our job!! No time wasted at all!

@BrainCrumbz
Copy link

Hi all. Hope this does not look too naive, quite new to Nx here.

We had this issue with a newly generated web application (i.e. through @nrwl/web:app), when serving the app.

By default, app project.json contains only production configuration, both in build and serve sections. Also, serve section did not include any defaultConfiguration explicitly.

We looked at another existing app (within the same OSS repo) and made the following additions to serve section (application name amended):

"serve": {
    // ...
    "defaultConfiguration": "development",
    // ...
    "configurations": {
        // ...
        "development": {
            "buildTarget": "XXX-XXX-XXX:build:development"
        }
    }
}

We also added the following development configuration to build section (for completeness, this should not really impact the issue):

"development": {
    "buildOptimizer": false,
    "optimization": false,
    "vendorChunk": true,
    "extractLicenses": false,
    "sourceMap": true,
    "namedChunks": true
}

After those changes, the warning went away. HTH

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.