You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When building the WASM glue with `-sENVIRONMENT=web,node`, Emscripten emits a Node-only branch that uses Node built-ins (`fs`, `path`, sometimes `crypto`). Some bundlers (notably **Next.js Turbopack**) will still try to resolve those built-ins when the module is imported from a Client Component and fail with **"Can't resolve 'fs'"**.
16
+
17
+
We keep a **single package** that works in both browser and Node by combining three measures:
18
+
19
+
-**Patch Emscripten glue to use `node:*` built-ins**
-`tsup.config.ts` sets `external: ["./grida-canvas-wasm"]` and copies `lib/bin/*` via `publicDir`
29
+
- Result: `dist/index.js` only imports `./grida-canvas-wasm`, and the actual glue stays as `dist/grida-canvas-wasm.js` (copied), so Turbopack never sees Node built-ins inside the bundled entry.
30
+
31
+
-**Run the glue patch before bundling**
32
+
-`package.json` uses `prebuild` to patch `lib/bin/grida-canvas-wasm.js` before `tsup` runs.
33
+
34
+
⚠️ Notes:
35
+
- Simply setting `tsup.external` to `["node:fs", "node:path", ...]` is **not sufficient** here; bundling the glue can still produce `require("fs")` in `dist/index.js`, which breaks Turbopack.
36
+
- If you change `lib/index.ts` to import `./bin/grida-canvas-wasm` directly (no wrapper + external), re-verify `pnpm --filter editor build` with Turbopack.
37
+
13
38
## Build System
14
39
15
40
This project uses a unified `justfile` build system for all WASM build configurations.
0 commit comments