nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Runtime config null/undefined values not overwritten by .env values

Open itpropro opened this issue 4 months ago • 1 comments

Environment

Latest nitro, Node 20

Reproduction

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

Describe the bug

Variables with the NITRO prefix defined in .env files are not replacing variables that are undefined/null in the nitro.config.ts. This is caused by how defu handles undefined/null values in c12 (https://github.com/unjs/c12/blob/e52c54171b3546cb9ee9233e6ca95221e2a5adfd/src/loader.ts#L169). The fix #907 didn't fix this problem, as in Nuxt, defaults are applied at a later point while in Nitro, the values are already stripped out by c12. I think this should be fixed in c12, so if you have a preferred way for this @pi0, I will create a PR there. We can use a custom merger for defu in c12 when defaults are applied or overwriting undefined/null before it goes to defu. This should probably be hidden behind a switch like provideFallbackValues, mergeUndefinedValues, etc. to avoid a breaking change.

Additional context

No response

Logs

No response

itpropro avatar Mar 16 '24 20:03 itpropro