mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #167] vite dev crashes: ssrLoadModule fails in configureServer when instrumentation.ts exists #38
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#38
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @southpolesteve on GitHub (Feb 27, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/167
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.@illegalcall commented on GitHub (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.