Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
itpropro opened this issue Mar 16, 2024 · 1 comment
Open
Labels
discussion enhancement New feature or request

Comments

@itpropro
Copy link
Contributor

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 itpropro changed the title Handling of runtime config from .env file Runtime config null/undefined values not overwritten by .env values Mar 16, 2024
@pi0 pi0 added enhancement New feature or request discussion and removed pending triage labels Jun 11, 2024
@pi0
Copy link
Member

pi0 commented Jun 11, 2024

A custom merger makes sense or alternatively, we can scan c12 layers (they contain original config) and collect list of known runtime config keys to scan.

Implicitly collecting build-time env values to assume as runtime config might lead to unexpected results so probably better we still require that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants