cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open noook opened this issue 1 year ago • 1 comments

Environment

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

noook avatar Mar 13 '24 14:03 noook