You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vitest 4 broke stubEnv(..., undefined) to unset an environment variable #10525
Sorry for the delay! I've identified the root cause — the metaEnv Proxy in worker.ts has get/set traps that use the live process.env, but is missing a deleteProperty trap. When user code replaces process.env (e.g. process.env = {}), the delete in stubEnv(key, undefined) operates on the stale Proxy target instead of the current process.env.
The fix is to add a deleteProperty trap. Opening a PR now.
Still happens on 5.0.3 (node 24.17.0) with the repro. Passes on 3.2.4, fails on 4.0.18 and later.
It only fails when process.env is reassigned (process.env = {}). Without that, stubEnv(key, undefined) works.
I tested adding a deleteProperty trap to the import.meta.env proxy in the installed vitest and the repro passed, so the cause clanzhang mentioned looks right. #10539 tried the same fix but was auto-closed. Would you accept a PR for this?
Activity
clanzhang commentedon Jun 14, 2026
I'd like to work on this. PR soon.
DamienCassou commentedon Jul 1, 2026
@clanzhang did you find anything?
clanzhang commentedon Jul 1, 2026
Sorry for the delay! I've identified the root cause — the metaEnv Proxy in worker.ts has get/set traps that use the live process.env, but is missing a deleteProperty trap. When user code replaces process.env (e.g. process.env = {}), the delete in stubEnv(key, undefined) operates on the stale Proxy target instead of the current process.env.
The fix is to add a deleteProperty trap. Opening a PR now.
DamienCassou commentedon Jul 29, 2026
@clanzhang Have you opened a PR?
clanzhang commentedon Aug 3, 2026
Sorry, I don't really want to submit this PR — seeing that person gives me PTSD. Please don't rush me into submitting the PR either. Thanks.
Prajwal2246 commentedon Oct 7, 2026
Still happens on 5.0.3 (node 24.17.0) with the repro. Passes on 3.2.4, fails on 4.0.18 and later.
It only fails when process.env is reassigned (process.env = {}). Without that, stubEnv(key, undefined) works.
I tested adding a deleteProperty trap to the import.meta.env proxy in the installed vitest and the repro passed, so the cause clanzhang mentioned looks right. #10539 tried the same fix but was auto-closed. Would you accept a PR for this?