nuxt icon indicating copy to clipboard operation
nuxt copied to clipboard

How do I make a custom env file work?

Open zhang-xxx opened this issue 3 weeks ago • 2 comments

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.

zhang-xxx avatar Dec 03 '25 03:12 zhang-xxx

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

Open v4 in Stackblitz Open v3 in Stackblitz

Open v4 in CodeSandbox Open v3 in CodeSandbox

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:

github-actions[bot] avatar Dec 03 '25 07:12 github-actions[bot]

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.

zhang-xxx avatar Dec 07 '25 05:12 zhang-xxx

have the same problem

HEI-cloud avatar Dec 17 '25 08:12 HEI-cloud