Description
vite dev crashes during server startup when the project has an instrumentation.ts (or src/instrumentation.ts) file. The configureServer hook calls server.ssrLoadModule() to load instrumentation, but Vite 7's SSRCompatModuleRunner fails because the SSR environment channel is not yet initialized at that point in the server lifecycle.
Error
file:///node_modules/vite/dist/node/chunks/config.js:15041
options$1.channel.api.outsideEmitter.on("send", onMessage);
^
TypeError: Cannot read properties of undefined (reading 'outsideEmitter')
at Object.connect (vite/dist/node/chunks/config.js:15041:26)
at new ModuleRunner (vite/dist/node/module-runner.js:1009:34)
at new SSRCompatModuleRunner (vite/dist/node/chunks/config.js:15097:3)
at ssrLoadModule (vite/dist/node/chunks/config.js:15076:36)
at runInstrumentation (vinext/dist/server/instrumentation.js:61:34)
at configureServer (vinext/dist/index.js:2101:21)
at _createServer (vite/dist/node/chunks/config.js:25603:97)
Repro
- Create a project with
src/instrumentation.ts that exports register() and/or onRequestError()
- Run
npx vite dev
- Server crashes immediately
Environment
- vinext 0.0.12
- Vite 7.3.1
- Node.js v24.3.0 (also reproduced on v22.1.0)
- Also fails under Bun
Root cause
In packages/vinext/src/index.ts, the configureServer hook calls runInstrumentation(server, instrumentationPath) which invokes server.ssrLoadModule(). In Vite 7, ssrLoadModule creates an SSRCompatModuleRunner that requires the SSR environment's transport channel to be initialized. During configureServer, the channel is not yet set up, so channel.api is undefined.
Workaround
Remove instrumentation.ts to prevent the code path from triggering. This is not viable for projects that need instrumentation (e.g., PostHog, Sentry).
Suggested fix
Defer the runInstrumentation call until after the server is fully initialized, for example by using the server's listen event or moving it into the returned middleware function.
Description
vite devcrashes during server startup when the project has aninstrumentation.ts(orsrc/instrumentation.ts) file. TheconfigureServerhook callsserver.ssrLoadModule()to load instrumentation, but Vite 7'sSSRCompatModuleRunnerfails because the SSR environment channel is not yet initialized at that point in the server lifecycle.Error
Repro
src/instrumentation.tsthat exportsregister()and/oronRequestError()npx vite devEnvironment
Root cause
In
packages/vinext/src/index.ts, theconfigureServerhook callsrunInstrumentation(server, instrumentationPath)which invokesserver.ssrLoadModule(). In Vite 7,ssrLoadModulecreates anSSRCompatModuleRunnerthat requires the SSR environment's transport channel to be initialized. DuringconfigureServer, the channel is not yet set up, sochannel.apiis undefined.Workaround
Remove
instrumentation.tsto prevent the code path from triggering. This is not viable for projects that need instrumentation (e.g., PostHog, Sentry).Suggested fix
Defer the
runInstrumentationcall until after the server is fully initialized, for example by using the server'slistenevent or moving it into the returned middleware function.