How do I make a custom env file work?
When I created two custom environment files: .env.development and .env.production, each containing a variable named NUXT_PUBLIC_CHAT_ORIGIN, and then configured the corresponding variable in nuxt.config.js
runtimeConfig: { public: { chatOrigin: process.env.NUXT_PUBLIC_CHAT_ORIGIN || 'http://192.168.70.41:5173/', }, }
I changed the package's execution command to
"build": "nuxt build --dotenv .env.production", "build:dev": "nuxt build --dotenv .env.development", "dev": "nuxt dev --dotenv .env.development",
However, when I execute the build:dev command locally, the variable from the .env.development file is not being written to runtimeConfig. Why is this? I want the variable to be written to runtimeConfig during the build phase.
Would you be able to provide a minimal reproduction? 🙏
More info
Why do I need to provide a reproduction?
Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.
What will happen?
If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect.
If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.
How can I create a reproduction?
Please use a template below to create a minimal reproduction
A public GitHub repository is also perfect. 👌
Please ensure that the reproduction is as minimal as possible. See more details in our guide.
You might also find these other articles interesting and/or helpful:
Would you be able to provide a minimal reproduction? 🙏 More info
Here is a minimal reproduction: https://github.com/zhang-xxx/nuxt4-runtimeconfig-env-repro Steps are in the README.
have the same problem