Skip to content

vite dev crashes: ssrLoadModule fails in configureServer when instrumentation.ts exists #167

Closed

Description

@southpolesteve

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

  1. Create a project with src/instrumentation.ts that exports register() and/or onRequestError()
  2. Run npx vite dev
  3. 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.

Activity

  1. illegalcall commented on Feb 27, 2026

    @illegalcall
    Contributor

    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:

    • vinext 0.0.12 + Vite 7.3.1
    • Node 22.14.0, Node 24.14.0, and Bun 1.2.21
    • npm, pnpm, and bun as package managers
    • Pages Router only and App Router (with app/ directory)
    • Symlinked vinext via file: dependency

    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:

    // vite.config.ts
    import { defineConfig, DevEnvironment } from "vite";
    export default defineConfig({
      environments: {
        ssr: {
          dev: {
            createEnvironment(name, config) {
              return new DevEnvironment(name, config, {});
            },
          },
        },
      },
    });
    

    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:

    1. Do you have any custom environments config or a plugin that overrides the SSR environment?
    2. Is there anything else in your setup beyond what's listed in the issue?

    That will help me target the fix correctly.

  2. added a commit that references this issue on Mar 6, 2026
    31791be
  3. added a commit that references this issue on Mar 7, 2026
    dc8e953
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions