Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nuxt build changes NODE_ENV #19819

Closed
rutgerbakker95 opened this issue Mar 20, 2023 · 5 comments
Closed

nuxt build changes NODE_ENV #19819

rutgerbakker95 opened this issue Mar 20, 2023 · 5 comments

Comments

@rutgerbakker95
Copy link

Environment

  • Operating System: Darwin
  • Node Version: v18.14.1
  • Nuxt Version: 3.3.1
  • Nitro Version: 2.3.1
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: srcDir, runtimeConfig, vite, modules, i18n, tailwindcss, apollo
  • Runtime Modules: @nuxtjs/i18n@8.0.0-beta.10, @nuxtjs/tailwindcss@6.6.0, @nuxtjs/apollo@5.0.0-alpha.5
  • Build Modules: -

Reproduction

[WARN] Changing NODE_ENV from staging to production, to avoid unintended behavior.

Describe the bug

Is there a way to prevent Nuxt from automatically changing NODE_ENV to production when I use export NODE_ENV=staging in my pipeline?

Additional context

No response

Logs

No response

@pi0
Copy link
Member

pi0 commented Mar 20, 2023

This was a required workaround we needed to do because tools such as postcss(plugins) was having unexpected behavior when NODE_ENV is not production. (cc @Atinux if you remember more).

WHat is your main usage for NODE_ENV = staging is it used for runtimeConfig or other logic conditions? (we might think about a temporary restore of user-provided env to resolve both logics, however can be tricky and more info would be nice)

@danielroe
Copy link
Member

I agree with @pi0. I don't think we can support alternative NODE_ENV values. This is not where you should set your app's environment; it's a protected Node environment variable with a limited list of valid values. I would recommend instead using APP_ENV or similar.

@rutgerbakker95
Copy link
Author

@pi0 Ah ok. I'm using three env files (.env, .env.production, .env.staging) which contains an API_HOST variable used on runtime. I can give it a shot and see if I can use only one file to store variables for different environments.

@danielroe
Copy link
Member

@rutgerbakker95 Nuxt does not have native support for reading .env files based on NODE_ENV (nor does it read in env files at all in production), so you could continue to split your config, but manually read them in based on APP_ENV or similar.

@rutgerbakker95
Copy link
Author

@danielroe Ok, I'll try to make it work with APP_ENV

@Atinux Atinux closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants