vitejs/vite · error · SendBeforeConnectError
send was called before connect
Error message
send was called before connect
What it means
Thrown by the normalized transport's send() when it is invoked before connect() has completed, with no in-flight connecting promise. The transport tracks an isConnected flag set only after connect resolves; sending earlier means messages would be dropped.
Solutions
- Always await transport.connect() (or runner's underlying connect) before sending.
- If using the ModuleRunner, ensure the runner is connected before importing modules — the runner normally manages this, so avoid calling transport.send manually.
- Catch SendBeforeConnectError (error.name === 'SendBeforeConnectError') and retry after awaiting connect.
Example fix
// before
transport.send({ type: 'custom', event: 'ping', data: {} }) // throws if not connected
// after
await transport.connect()
transport.send({ type: 'custom', event: 'ping', data: {} }) Defensive patterns
Strategy: validation
Validate before calling
await transport.connect() await transport.send(payload)
Try / catch
try {
await transport.send(payload)
} catch (e) {
if (e?.name === 'SendBeforeConnectError') {
await transport.connect()
await transport.send(payload)
} else throw e
} Prevention
- Always await connect() before send().
- Let the ModuleRunner manage connect lifecycle; avoid manual transport.send.
When it happens
Trigger: Calling transport.send(payload) before awaiting transport.connect(). Throws SendBeforeConnectError at moduleRunnerTransport.ts:240 when isConnected is false and there is no connectingPromise.
Common situations: Custom code that constructs a runner/transport and immediately sends without waiting for connect. A race where the module runner is asked to fetch before the WebSocket/emitter connection is established. Forgetting to await an async connect in a bootstrap sequence.
Related errors
- invoke was called before connect
- Cannot send non-custom events from the client to the server.
- Cannot send non-custom events from the server to the client.
- HMR is not supported by this runner transport, but `hmr`…
- [module runner] Failed to load
AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11).
Data as JSON: /api/errors/b0bb8f464c398d31.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vite/src/shared/moduleRunnerTransport.ts:240
? {
async disconnect() {
if (!isConnected) return
if (connectingPromise) {
await connectingPromise
}
isConnected = false
await invokeableTransport.disconnect!()
},
}
: {}),
async send(data) {
if (!invokeableTransport.send) return
if (!isConnected) {
if (connectingPromise) {
await connectingPromise
} else {
throw new SendBeforeConnectError('send was called before connect')
}
}
await invokeableTransport.send(data)
},
async invoke(name, data) {
if (!isConnected) {
if (connectingPromise) {
await connectingPromise
} else {
throw new SendBeforeConnectError('invoke was called before connect')
}
}
return invokeableTransport.invoke(name, data)
},
}
}
export class SendBeforeConnectError extends Error {View on GitHub (pinned to b4d66fee14)