cli
cli copied to clipboard
Nuxt reads a different env file if value is not found in the configured env file
Environment
- Operating System:
Darwin - Node Version:
v21.6.2 - Nuxt Version:
3.10.3 - CLI Version:
3.10.1 - Nitro Version:
2.9.3 - Package Manager:
[email protected] - Builder:
- - User Config:
devtools,typescript,colorMode,modules,runtimeConfig,nitro,tailwindcss,supabase,experimental - Runtime Modules:
@nuxtjs/[email protected],@nuxt/[email protected],@nuxt/[email protected],@vueuse/[email protected] - Build Modules:
-
Reproduction
https://stackblitz.com/edit/github-xxfchy
Describe the bug
- Configure
.envand.env.local. In this example,.envrefers to the template,.env.localrefer to the actual values - Keep the template env property empty
- Do not define it in
.env.local(letnuxt.config.tsuse the default value of runtime config) - Run nuxt with
nuxt dev --dotenv .env.local - Nuxt fallbacks on
.envfile's values if it doesn't find it in the configured env file.env.local
Additional context
I digged a bit and I can't tell whether the issue comes from @nuxt/cli or @nuxt/kit. I noticed sometimes the dotenv property is not passed as a string but casted as a boolean, which makes dotenv load the default env file (.env) instead of the one configured
const opts = {
// ...
dotenv: !!ctx.args.dotenv,
// ...
}
Logs
No response