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

runtime config in .env is not loaded in production #28698

Closed
kingyue737 opened this issue Aug 25, 2024 · 3 comments
Closed

runtime config in .env is not loaded in production #28698

kingyue737 opened this issue Aug 25, 2024 · 3 comments

Comments

@kingyue737
Copy link

Environment


  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.13.0
  • CLI Version: 3.13.0
  • Nitro Version: 2.9.7
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: compatibilityDate, devtools, runtimeConfig
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-p9jzzh

Describe the bug

I added NUXT_TEST=reproduction in .env file. It works well in dev and the string reproduction is rendered in page.

But if I build it and preview with node .output/server/index.mjs, the config in .env does not take effect.

Additional context

No response

Logs

No response

Copy link

stackblitz bot commented Aug 25, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@danielroe
Copy link
Member

This is documented behaviour: https://nuxt.com/docs/guide/directory-structure/env#production

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Aug 26, 2024
@kingyue737
Copy link
Author

Sorry for missing that part in the documentation. For those who want to load .env in production, we can use the built-in functionality since Node v20.6: https://nodejs.org/en/learn/command-line/how-to-read-environment-variables-from-nodejs

node --env-file=.env .output/server/index.mjs

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

2 participants