Skip to content

Commit 48a72ed

Browse files
authored
Merge pull request #140 from launchql/feat/with-workers
Feat/with workers
2 parents f97b0e1 + 9e693d6 commit 48a72ed

File tree

9 files changed

+47
-7
lines changed

9 files changed

+47
-7
lines changed

LOADING_WASM.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### ⚙️ TL;DR — Serving the `.wasm` File
2+
3+
The core issue isn’t the library — it’s that the **`.wasm` file lives in `node_modules` and isn’t automatically served** by Next.js, Webpack, or Turbopack.
4+
You just need to make sure it’s fetchable at runtime.
5+
6+
#### ✅ Easiest Fix
7+
8+
Copy the `.wasm` file once and serve it from `/public`:
9+
10+
```bash
11+
cp node_modules/libpg-query/wasm/libpg-query.wasm public/
12+
```
13+
14+
#### ⚠️ Why
15+
16+
Bundlers don’t emit `.wasm` files by default — they stay inside `node_modules`, so the runtime can’t fetch them.
17+
18+
#### 🧩 Workarounds
19+
20+
* **Next.js + Webpack:** Add a `.wasm` asset rule or use the copy method.
21+
* **Turbopack:** Only the copy method works for now.
22+
* **Dev mode:** Optionally use a watcher script to auto-copy on rebuilds.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ pnpm run test
185185
- Ensure Emscripten SDK is properly installed and configured
186186
- Check that all required build dependencies are available
187187

188+
**`.wasm` not found**
189+
- Usually occurs in Next.js/Webpack/Turbopack
190+
- see **[LOADING_WASM.md](./LOADING_WASM.md)**
191+
188192
### Template System
189193

190194
To avoid duplication across PostgreSQL versions, common files are maintained in the `templates/` directory:

full/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ ifdef EMSCRIPTEN
6060
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query','_wasm_parse_query_protobuf','_wasm_get_protobuf_len','_wasm_deparse_protobuf','_wasm_parse_plpgsql','_wasm_fingerprint','_wasm_normalize_query','_wasm_scan','_wasm_parse_query_detailed','_wasm_free_detailed_result','_wasm_free_string','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6161
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','UTF8ToString','getValue','HEAPU8','HEAPU32']" \
6262
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
63-
-sENVIRONMENT="web,node" \
63+
-sENVIRONMENT="web,node,worker" \
64+
-sASSERTIONS=0 \
65+
-sSINGLE_FILE=0 \
6466
-sMODULARIZE=1 \
6567
-sEXPORT_ES6=0 \
6668
-sALLOW_MEMORY_GROWTH=1 \

templates/Makefile.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ ifdef EMSCRIPTEN
6565
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6666
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
6767
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
68-
-sENVIRONMENT="web,node" \
68+
-sENVIRONMENT="web,node,worker" \
69+
-sASSERTIONS=0 \
70+
-sSINGLE_FILE=0 \
6971
-sMODULARIZE=1 \
7072
-sEXPORT_ES6=0 \
7173
-sALLOW_MEMORY_GROWTH=1 \

versions/13/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ ifdef EMSCRIPTEN
6868
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6969
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
7070
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
71-
-sENVIRONMENT="web,node" \
71+
-sENVIRONMENT="web,node,worker" \
72+
-sASSERTIONS=0 \
73+
-sSINGLE_FILE=0 \
7274
-sMODULARIZE=1 \
7375
-sEXPORT_ES6=0 \
7476
-sALLOW_MEMORY_GROWTH=1 \

versions/14/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ ifdef EMSCRIPTEN
6565
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6666
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
6767
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
68-
-sENVIRONMENT="web,node" \
68+
-sENVIRONMENT="web,node,worker" \
69+
-sASSERTIONS=0 \
70+
-sSINGLE_FILE=0 \
6971
-sMODULARIZE=1 \
7072
-sEXPORT_ES6=0 \
7173
-sALLOW_MEMORY_GROWTH=1 \

versions/15/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ ifdef EMSCRIPTEN
6767
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6868
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
6969
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
70-
-sENVIRONMENT="web,node" \
70+
-sENVIRONMENT="web,node,worker" \
71+
-sASSERTIONS=0 \
72+
-sSINGLE_FILE=0 \
7173
-sMODULARIZE=1 \
7274
-sEXPORT_ES6=0 \
7375
-sALLOW_MEMORY_GROWTH=1 \

versions/16/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ ifdef EMSCRIPTEN
6565
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6666
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
6767
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
68-
-sENVIRONMENT="web,node" \
68+
-sENVIRONMENT="web,node,worker" \
69+
-sASSERTIONS=0 \
70+
-sSINGLE_FILE=0 \
6971
-sMODULARIZE=1 \
7072
-sEXPORT_ES6=0 \
7173
-sALLOW_MEMORY_GROWTH=1 \

versions/17/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ ifdef EMSCRIPTEN
6565
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6666
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
6767
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
68-
-sENVIRONMENT="web,node" \
68+
-sENVIRONMENT="web,node,worker" \
69+
-sASSERTIONS=0 \
70+
-sSINGLE_FILE=0 \
6971
-sMODULARIZE=1 \
7072
-sEXPORT_ES6=0 \
7173
-sALLOW_MEMORY_GROWTH=1 \

0 commit comments

Comments
 (0)