cli icon indicating copy to clipboard operation
cli copied to clipboard

Ability to keep NODE_ENV as it was set during build

Open smil2k opened this issue 2 years ago • 6 comments

Describe the feature

Currently nuxt build overrides NODE_ENV to production, which is not always desirable.

We have staging builds, which require the inclusion of different keys, currently it is not possible to use the intented NODE_ENV variable for this.

Suggestion is to add a flag to omit this override feature, defaulting to false: meaning without this flag, the build will override.

Additional information

  • [X] Would you be willing to help implement this feature?
  • [ ] Could this feature be implemented as a module?

Final checks

smil2k avatar Sep 07 '23 13:09 smil2k

As a workaround, you could use another env variable to differentiate between staging/prod/dev/... 🤔

TheAlexLichter avatar Sep 07 '23 13:09 TheAlexLichter

Thank you for the suggestion. I'll override it again in nuxt.config.js.

smil2k avatar Sep 07 '23 14:09 smil2k

Best would be to not use NODE_ENV for that but something like STAGE/APP_ENV/...

TheAlexLichter avatar Sep 07 '23 18:09 TheAlexLichter

I would very strongly advise against overriding NODE_ENV. It is really not meant for distinguishing between staging/prod/dev modes and will break any number of dependencies along the way.

danielroe avatar Sep 10 '23 08:09 danielroe

I would also strongly recommend depending on two development and production values for NODE_ENV. There is no standard that tells not to use other values but there were strong reasons that Nuxt CLI makes sure it remains within these two values. Many packages in node_modules can be misbehaving and assuming your application should be in development conditions when something like staging is used.

But regardless i think we should give an out of the box alternative env name to access original one (currently nuxi only makes a warn + force override)

pi0 avatar Sep 10 '23 12:09 pi0

(Linking #357)

TheAlexLichter avatar Apr 26 '24 07:04 TheAlexLichter