Describe the bug
If a dev environment transforms a module that imports a bare specifier between createServer() and server.listen(), the deps optimizer can crash while committing the pre-bundle:
[vite] (ssr) error while updating dependencies:
TypeError: Cannot read properties of undefined (reading 'browserHash')
at commitProcessing (…/vite/dist/node/chunks/node.js:33347:134)
at async runOptimizer (…/vite/dist/node/chunks/node.js:33364:5)
Calling transformRequest() before listen() is common in practice — framework integrations eagerly load modules during server setup — so in real projects this surfaces as an intermittent, timing-dependent error at dev-server startup. We see it regularly with astro dev (Astro transforms an internal module during startup); it is more likely with cold OS file caches (first run of the day, right after installing dependencies).
After the error, the affected environment's already-discovered deps appear to be forgotten, so the session can go on to re-discover and re-bundle deps it had already processed.
The linked reproduction triggers the error deterministically by importing a dependency that is slow enough to pre-bundle (lodash-es) that the bundle is still in flight when listen() runs.
Reproduction
https://stackblitz.com/github/adamchal/mre-vite-optimizer-browserhash (source: https://github.com/adamchal/mre-vite-optimizer-browserhash)
Steps to reproduce
npm install — the repro runs automatically via postinstall (re-run any time with node repro.mjs)
On the StackBlitz link the error appears in the terminal during the automatic install, at the end of the postinstall output.
The repro script: creates a server with an ssr environment with dep optimization enabled (optimizeDeps.noDiscovery: false, resolve.noExternal: true), calls transformRequest("/entry.js") (which imports lodash-es) before listen(), waits 120ms for the optimizer's debounced pre-bundle to start, then calls server.listen() while it is in flight.
System Info
vite: 8.1.3
node: v26.3.1
OS: macOS 15.7.7 (also observed on Linux)
Used Package Manager
npm
Describe the bug
If a dev environment transforms a module that imports a bare specifier between
createServer()andserver.listen(), the deps optimizer can crash while committing the pre-bundle:Calling
transformRequest()beforelisten()is common in practice — framework integrations eagerly load modules during server setup — so in real projects this surfaces as an intermittent, timing-dependent error at dev-server startup. We see it regularly withastro dev(Astro transforms an internal module during startup); it is more likely with cold OS file caches (first run of the day, right after installing dependencies).After the error, the affected environment's already-discovered deps appear to be forgotten, so the session can go on to re-discover and re-bundle deps it had already processed.
The linked reproduction triggers the error deterministically by importing a dependency that is slow enough to pre-bundle (
lodash-es) that the bundle is still in flight whenlisten()runs.Reproduction
https://stackblitz.com/github/adamchal/mre-vite-optimizer-browserhash (source: https://github.com/adamchal/mre-vite-optimizer-browserhash)
Steps to reproduce
npm install— the repro runs automatically viapostinstall(re-run any time withnode repro.mjs)On the StackBlitz link the error appears in the terminal during the automatic install, at the end of the
postinstalloutput.The repro script: creates a server with an
ssrenvironment with dep optimization enabled (optimizeDeps.noDiscovery: false,resolve.noExternal: true), callstransformRequest("/entry.js")(which importslodash-es) beforelisten(), waits 120ms for the optimizer's debounced pre-bundle to start, then callsserver.listen()while it is in flight.System Info
Used Package Manager
npm