Indeed the nx builder will replace the expression process.env.NODE_ENV
in our source code with the current value of the env var (or the nx-mode).
What happens is this:
Since the webpack-define plugin will look for the text process.env.NODE_ENV
, it's easy to use a workaround as explained in this answer:
process.env['NODE'+'_ENV']
Warning
When you need to apply this workaround to make your app work, then something is wrong. Since you have compiled your app in production mode, it does not make sense to pass another value for NODE_ENV
when you start the (production) app.
The webpack Production page contains some helpful info.
We also had this case, and the issue was, that we relied on the NODE_ENV
variable to load different database configs for dev, prod, test, etc.
The solution for our case was to simply use separate env-vars for the database config (e.g. DB_NAME
, DB_PORT
, ..), so that we can use different db-configs at runtime with any build-variants: dev, prod, test, etc.