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
Module runner: export * from a module still evaluating in a cycle never gets its later exports (undefined where Node has the value) #24183
Written with the help of an AI coding agent (Claude); reproduced locally.
Describe the bug
When b.js does export * from './a.js' while a.js is still evaluating (an import cycle), b.js never gets the exports a.js gains afterwards through its own export *. Reading b.js's export after the whole graph has finished gives undefined; native ESM gives the value. Swapping the two imports in entry.js makes it work.
// repro.mjs (with "type": "module" in package.json)import{createServer}from'vite'// Native ESMconstnative=awaitimport('./entry.js')console.log('node:',native.result)// Vite SSR (module runner)constserver=awaitcreateServer({configFile: false,appType: 'custom'})constviaVite=awaitserver.ssrLoadModule('/entry.js')console.log('vite:',viaVite.result)awaitserver.close()
npm install vite
node repro.mjs
Actual (8.3.8, 8.4.0-beta.1, 7.3.8; same with server.environments.ssr.runner.import):
Expected: vite: { fromA: 42, fromB: 42 }. Star exports are resolved at link time, so b.js's value is leaf.js's binding whatever the evaluation order, and entry.js runs after all of them. After the load, Object.keys of b.js's namespace is [] in Vite and ['value'] in Node.
Likely spot: exportAll in module-runner/runner.ts copies the source's keys once, when the export * runs, and a.js has no keys yet at that point.
Related: #22491 (same family, but there the missing export is only missing during the cycle; PR #22493 does not cover this graph, which has no earlier import of the same source).
System Info
Vite 8.3.8, 8.4.0-beta.1, 7.3.8
Node 26.12.1, Linux x64
Reproduced on 8.3.8 with your exact files — Node gives { fromA: 42, fromB: 42 }, Vite gives { fromA: 42, fromB: undefined }, and after the load b.js's namespace keys are [] in Vite vs ['value'] in Node.
Your likely spot is right. exportAll in module-runner.js copies the source's keys once, when the export * statement runs, defining a live getter per key. In this graph a.js starts evaluating first; its export * from './b.js' starts b.js, and b.js's export * from './a.js' runs while a.js still has no keys — its own export * from './leaf.js' hasn't run yet — so nothing is copied, and nothing ever re-runs exportAll for b.js afterwards. a.js picks up value later because by the time its export * from './leaf.js' runs, leaf has evaluated.
So the copy is a snapshot of the keys at that moment, not the live binding set star exports are supposed to be. The getter it defines does read live (get: () => sourceModule[key]), but only for keys that existed when it ran. A fix would need b.js's namespace to gain the key when a.js gains it afterwards — either re-running the copy when the source module finishes evaluating, or resolving the re-export lazily so the key appears once the source has it.
Activity
abhi478jeetur-rgb commentedon Nov 23, 2026
Reproduced on 8.3.8 with your exact files — Node gives
{ fromA: 42, fromB: 42 }, Vite gives{ fromA: 42, fromB: undefined }, and after the loadb.js's namespace keys are[]in Vite vs['value']in Node.Your likely spot is right.
exportAllinmodule-runner.jscopies the source's keys once, when theexport *statement runs, defining a live getter per key. In this grapha.jsstarts evaluating first; itsexport * from './b.js'startsb.js, andb.js'sexport * from './a.js'runs whilea.jsstill has no keys — its ownexport * from './leaf.js'hasn't run yet — so nothing is copied, and nothing ever re-runsexportAllforb.jsafterwards.a.jspicks upvaluelater because by the time itsexport * from './leaf.js'runs,leafhas evaluated.So the copy is a snapshot of the keys at that moment, not the live binding set star exports are supposed to be. The getter it defines does read live (
get: () => sourceModule[key]), but only for keys that existed when it ran. A fix would needb.js's namespace to gain the key whena.jsgains it afterwards — either re-running the copy when the source module finishes evaluating, or resolving the re-export lazily so the key appears once the source has it.fix(module-runner): forward `export *` keys gained later in an import…