nuxt/cli

Nuxt reads a different env file if value is not found in the configured env file

noook opened this issue · 1 comments

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: pnpm@8.15.4
  • Builder: -
  • User Config: devtools, typescript, colorMode, modules, runtimeConfig, nitro, tailwindcss, supabase, experimental
  • Runtime Modules: @nuxtjs/supabase@1.1.7, @nuxt/ui@2.14.2-28504661.f4a48f6, @nuxt/fonts@0.0.2, @vueuse/nuxt@10.9.0
  • Build Modules: -

Reproduction

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

Describe the bug

  1. Configure .env and .env.local. In this example, .env refers to the template, .env.local refer to the actual values
  2. Keep the template env property empty
  3. Do not define it in .env.local (let nuxt.config.ts use the default value of runtime config)
  4. Run nuxt with nuxt dev --dotenv .env.local
  5. Nuxt fallbacks on .env file'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