Related issue:
This repo shows a build-time error when using @surrealdb/wasm (specifically createWasmWorkerEngines) in a Vite-based app.
The important detail is that the failure only happens at build time. Dev mode can work, but vite build fails because the Vite optimizer tries to analyze a new URL(...) call inside the compiled WASM wrapper.
pnpm install
pnpm run build
Using the documented worker API:
import { Surreal } from "surrealdb";
import { createWasmWorkerEngines } from "@surrealdb/wasm";
const db = new Surreal({
engines: createWasmWorkerEngines(),
});
Vite should successfully build the project. Internally, @surrealdb/wasm should expose a worker entry that’s friendly to Vite’s build-time analysis.
pnpm run dev can work.pnpm run build fails with an error about resolving / analyzing new URL inside the @surrealdb/wasm implementation.From what I can tell:
@surrealdb/wasm bundle as a dependency and tries to statically analyze a new URL(...) call inside it at build time.new URL call is not in the new URL("./worker.js", import.meta.url) shape that Vite expects, so the optimizer fails and build breaks.A Vite-friendly solution would be something like:
new URL("./worker.js", import.meta.url) (or similar), andundefinedWe use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.