NODE_ENV and stages

I have a solution where I’ve set up multiple stages (dev, test, prod) and environment variables for each of those stages. Works great - except when it comes to the NODE_ENV variable. In my lambda, when I’m running offline (serverless-offline) and I reference process.env.NODE_ENV, the value is “development”. Once I deploy, it’s value is “production”. I’m wanting to know when/how this value is set. I can’t seem to override it with environment variables. Ideally, I’d like to simulate the “production” value when I run offline (via serverless-offline). Has anyone ran into this scenario or have any answers to this?

1 Like

This is likely webpack enforcing NODE_ENV value setting it to production. I’ve solved this by adding the following to my webpack config:

optimization: {
    nodeEnv: false
  }
1 Like

This is likely webpack enforcing NODE_ENV value setting it to production.

1 Like