Runtime Already Initialized Error
Trace attempts to replace an SER runtime after work has claimed its singleton.What this error means and what can trigger it
RuntimeAlreadyInitializedError means ClientRuntime.make(...) or ServerRuntime.make(...) tried to configure a runtime after one already existed.
The first runtime does not have to come from an explicit make call. Client code may install the default dispatcher lazily through get_dispatcher(), while server code can do the same with an empty runtime through get_server_runtime_or_throw(). A later make(layer) still fails because generated work may already hold the original runtime.
Vite development SSR has one intentional exception: during HMR, SER disposes the previous server runtime and accepts a replacement. Production, tests, and other environments keep the duplicate-initialization guard.
Exactly where it triggers
Client runtime:
static make<R = never>(layer?: Layer.Layer<R>): Dispatcher {
if (current_dispatcher) {
throw new RuntimeAlreadyInitializedError("ClientRuntime");
}Server runtime:
const should_replace_dev_runtime = current_server_runtime !== undefined && is_vite_dev_ssr();
if (current_server_runtime && !should_replace_dev_runtime) {
throw new RuntimeAlreadyInitializedError("ServerRuntime");
}Both are synchronous throws. For reference, the class itself is declared at modules/svelte-effect-runtime/src/errors.ts L564 @ C14.
Why this is the case
Dispatchers, fibers, caches, provided layers, and generated handlers need one stable runtime identity in each environment. Replacing it after initialization would leave earlier work attached to one runtime while later work sees another.
The HMR exception is scoped to Vite development SSR because reevaluating hooks.server.ts is expected there. SER disposes the previous instance before replacement rather than allowing two active server runtimes.