nx icon indicating copy to clipboard operation
nx copied to clipboard

Webpack's "interpolateEnvironmentVariablesToIndex" defaults to NODE_ENV=development

Open vergilfromadyen opened this issue 1 year ago • 6 comments

Current Behavior

I'm investigating an issue where my build sometimes runs in development mode by default. In the course of my investigation I found a possible bug.

The "getClientEnvironment" function defaults to NODE_ENV=development in this file.

This looks to be at odds with the executor as defined here.

Is this on purpose?

Expected Behavior

The default mode should be consistent

vergilfromadyen avatar Mar 28 '24 16:03 vergilfromadyen

@vergilfromadyen There shouldn't be a conflict there as the executor sets NODE_ENV first, which is read in by the interpolate function.

Note that nx serve will be in development, and build will be production. You can override that by using NODE_ENV=staging nx serve, or setting something in your .env file.

Can you link a repro so we can debug this better?

jaysoo avatar Apr 05 '24 13:04 jaysoo

Thanks for replying @jaysoo.

Can't really point you to a repo, our setup is all sorts of a weird mix of gradle, vite, and webpack, and I ultimately traced my issue elsewhere.

But I did read quite a bit of code here and this part stood out so I opened an issue to flag it as something I didn't expect to see. Please do feel free to close if it's purposefully built like that and not a bug.

vergilfromadyen avatar Apr 08 '24 14:04 vergilfromadyen

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar Apr 23 '24 00:04 github-actions[bot]

Oh wow, i have the same issue, but then with vite! And only on our CI agents. I have a console.log(prcess.env.NODE_ENV) in my vite config, and locally it is 'prodcution' but on my CI it is 'production' if i run "vite build", but 'development' if i run "nx build"

stefanlivens avatar May 06 '24 13:05 stefanlivens

Oh wow, i have the same issue, but then with vite! And only on our CI agents. I have a console.log(prcess.env.NODE_ENV) in my vite config, and locally it is 'prodcution' but on my CI it is 'production' if i run "vite build", but 'development' if i run "nx build"

@stefanlivens I forgot to update the issue but Vite assumes NODE_ENV=development by default, potentially here. I haven't looked too far in the source code to figure out why this isn't the same as locally.

Have you maybe renamed your buildTargetName to something other than build? I recall Vite has a convenient API to read the name of the command you're running, I wonder if it has to do with that.

vergilfromadyen avatar May 06 '24 14:05 vergilfromadyen

@vergilfromadyen thanks for answering, but alas. I'm pretty sure it is linked to nx!

This works without a problem locally, and (before adding @nx/vite to this project) also in our CI Pipeline.

So only since adding @nx/plugin to this project, this NODE_ENV is set to 'development' while building. I'm running a default setup from @nx/vite, no renaming of the default naming, so i was expecting this to 'just work'

stefanlivens avatar May 06 '24 15:05 stefanlivens

This issue has been automatically marked as stale because no reproduction was provided within 7 days. Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue. Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues. This issue will be closed in 21 days if a reproduction is not provided. If a reproduction has been provided, please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar May 14 '24 00:05 github-actions[bot]

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[bot] avatar Jul 06 '24 00:07 github-actions[bot]