nitrojs / nitrojs/nitro

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

Open
#2,270 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue from the linked StackBlitz example, then inspect the c12 loader at src/loader.ts around line 169 and the Nitro runtime configuration path involving nitro.config.ts. Determine how null or undefined values are handled before defu merges .env values; done means NITRO-prefixed .env values replace those configuration values without an unintended breaking change.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.