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
vite dev crashes: ssrLoadModule fails in configureServer when instrumentation.ts exists #167
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.
With the default config, Vite creates a RunnableDevEnvironment for SSR which has hot.api already initialized before configureServer runs — so there's no timing issue.
Could you share your exact reproduction project or vite.config.ts? Specifically:
Do you have any custom environments config or a plugin that overrides the SSR environment?
Is there anything else in your setup beyond what's listed in the issue?
Activity
illegalcall commentedon Feb 27, 2026
Hey @southpolesteve, thanks for filing this. I've been trying to reproduce the crash but haven't been able to trigger it with the setup described.
What I've tried:
In all cases, src/instrumentation.ts with a register() export loads fine — no crash.
The only way I could reproduce the exact outsideEmitter error was by explicitly overriding the SSR environment with a plain DevEnvironment:
With the default config, Vite creates a RunnableDevEnvironment for SSR which has hot.api already initialized before configureServer runs — so there's no timing issue.
Could you share your exact reproduction project or vite.config.ts? Specifically:
That will help me target the fix correctly.
fix(instrumentation): defer ssrLoadModule call to post-middleware hook
fix(instrumentation): defer ssrLoadModule to post-middleware hook (#289)