Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MRE: TypeError: Cannot read properties of undefined (reading 'browserHash') in the Deps Optimizer

When 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)

Transforming before listen() is what framework integrations do when they eagerly load a module during setup, so in real projects this surfaces as an intermittent, timing-dependent error at dev-server startup.

Reproduce

npm install

The repro runs automatically via postinstall; re-run it any time with node repro.mjs.

repro.mjs:

  1. creates a Vite server with an ssr environment that has dep optimization enabled (optimizeDeps.noDiscovery: false, resolve.noExternal: true),
  2. calls transformRequest("/entry.js") (which imports lodash-es) before listen(),
  3. waits 120ms (the optimizer discovers the dep and starts pre-bundling on a 100ms debounce),
  4. calls server.listen() while that pre-bundle is in flight.

Expected

The dep is pre-bundled without errors (or, at worst, is re-discovered after startup).

Actual

[vite] (ssr) error while updating dependencies:
TypeError: Cannot read properties of undefined (reading 'browserHash')
    at commitProcessing (…)
    at async runOptimizer (…)

Reproduces deterministically with this repro. In real projects the same error appears intermittently at dev startup — it depends on the pre-bundle still being in flight when listen() runs, so it is more likely with cold OS file caches (first run of the day, right after installing dependencies).

Environment

  • vite 8.1.3
  • Node v26.3.1
  • macOS 15.7.7 (also observed on Linux)

About

MRE: Vite deps optimizer TypeError (reading 'browserHash') when a module is transformed before server.listen()

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages