question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running nx serve on a React app serves it in production mode

See original GitHub issue

Current Behavior

A react application being served with nx serve is served in production mode. Also, you get the following warning:

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

See https://github.com/nrwl/nx/issues/7924

Expected Behavior

I expect that when I run my frontend application with nx serve, it is run in development mode with no warnings.

This seems to be a regression. I was not getting this issue in 13.8.3, and in fact reverting the @nrwl/* package versions back to 13.8.3 fixed the issue.

Steps to Reproduce

  1. Create a new react+express workspace using npx create-nx-workspace temp
    • Make sure to pick react-express for “What to create in the new workspace”
    • Make sure to pick scss for “Default stylesheet format”
  2. add console.log(environment.production); somewhere in the function definition of the App component. Make sure to import environment from ../environments/environment, and not ../environments/environment.prod
  3. run nx serve temp to run the react application
  4. You will notice the following warning pop up in the logs:
    WARNING in DefinePlugin
    Conflicting values for 'process.env.NODE_ENV'
    
  5. You will see true printing in the browser console, indicating that the environment.ts file replacement was done, and therefore that the production mode was turned on

Failure Logs

$ nx serve temp

> nx run temp:serve

<i> [webpack-dev-server] [HPM] Proxy created: /api  -> http://localhost:3333
<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.2 MiB = runtime.js 47.4 KiB main.js 1.15 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.15 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 (2cea0dd97d817b81)

Environment

$ nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.13.2
   OS   : linux x64
   npm  : 8.1.2
   
   nx : 13.8.5
   @nrwl/angular : undefined
   @nrwl/cli : 13.8.5
   @nrwl/cypress : 13.8.5
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.5
   @nrwl/eslint-plugin-nx : 13.8.5
   @nrwl/express : 13.8.5
   @nrwl/jest : 13.8.5
   @nrwl/js : 13.8.5
   @nrwl/linter : 13.8.5
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : 13.8.5
   @nrwl/nx-cloud : undefined
   @nrwl/react : 13.8.5
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.8.5
   @nrwl/tao : 13.8.5
   @nrwl/web : 13.8.5
   @nrwl/workspace : 13.8.5
   typescript : 4.5.5
   rxjs : 6.6.7
   ---------------------------------------
   Community plugins:

(node:148486) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at /home/cris/dev/temp/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
owen26commented, Mar 9, 2022

You should be able to fix this by either

change your serve target buildTarget option from PROJECT_NAME:build to PROJECT_NAME:build:development

or

change your build target defaultConfiguration option from production to development, or simply removes this setting

1reaction
cristian-aldeacommented, Mar 13, 2022

I’m thinking of closing down this issue, since it seems my issue has the same root cause as #7924

thank you to all who looked into the issue and informed everyone of how to address it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run nrwl/nx production build of web app on localhost ...
After building, next start starts a Node.js server that supports hybrid pages, serving both statically generated and server-side rendered pages.
Read more >
Building an application with React and Nx - LogRocket Blog
Create an application React and Nx, a build framework that allows you to build monorepos and scaffold full applications in place.
Read more >
️ Local HTTPS for React app in Nx workspace
Hey, welcome back in this post series where we will see how to setup a full HTTPS development environment. In this post, we...
Read more >
The React CLI you always wanted but didn't know about
Serving our React app. To serve our React app, run npx nx serve happynrwl. Note I prefix the commands with npx , which...
Read more >
Effective React Development with Nx
building and running our application in production mode. ... Restart the development server again (nx serve bookstore), and you should see.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found