Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions LOADING_WASM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### ⚙️ TL;DR — Serving the `.wasm` File

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.
You just need to make sure it’s fetchable at runtime.

#### ✅ Easiest Fix

Copy the `.wasm` file once and serve it from `/public`:

```bash
cp node_modules/libpg-query/wasm/libpg-query.wasm public/
```

#### ⚠️ Why

Bundlers don’t emit `.wasm` files by default — they stay inside `node_modules`, so the runtime can’t fetch them.

#### 🧩 Workarounds

* **Next.js + Webpack:** Add a `.wasm` asset rule or use the copy method.
* **Turbopack:** Only the copy method works for now.
* **Dev mode:** Optionally use a watcher script to auto-copy on rebuilds.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ pnpm run test
- Ensure Emscripten SDK is properly installed and configured
- Check that all required build dependencies are available

**`.wasm` not found**
- Usually occurs in Next.js/Webpack/Turbopack
- see **[LOADING_WASM.md](./LOADING_WASM.md)**

### Template System

To avoid duplication across PostgreSQL versions, common files are maintained in the `templates/` directory:
Expand Down
4 changes: 3 additions & 1 deletion full/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ ifdef EMSCRIPTEN
-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']" \
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','UTF8ToString','getValue','HEAPU8','HEAPU32']" \
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
-sENVIRONMENT="web,node" \
-sENVIRONMENT="web,node,worker" \
-sASSERTIONS=0 \
-sSINGLE_FILE=0 \
-sMODULARIZE=1 \
-sEXPORT_ES6=0 \
-sALLOW_MEMORY_GROWTH=1 \
Expand Down
4 changes: 3 additions & 1 deletion templates/Makefile.template
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ ifdef EMSCRIPTEN
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
-sENVIRONMENT="web,node" \
-sENVIRONMENT="web,node,worker" \
-sASSERTIONS=0 \
-sSINGLE_FILE=0 \
-sMODULARIZE=1 \
-sEXPORT_ES6=0 \
-sALLOW_MEMORY_GROWTH=1 \
Expand Down
4 changes: 3 additions & 1 deletion versions/13/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ ifdef EMSCRIPTEN
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
-sENVIRONMENT="web,node" \
-sENVIRONMENT="web,node,worker" \
-sASSERTIONS=0 \
-sSINGLE_FILE=0 \
-sMODULARIZE=1 \
-sEXPORT_ES6=0 \
-sALLOW_MEMORY_GROWTH=1 \
Expand Down
4 changes: 3 additions & 1 deletion versions/14/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ ifdef EMSCRIPTEN
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
-sENVIRONMENT="web,node" \
-sENVIRONMENT="web,node,worker" \
-sASSERTIONS=0 \
-sSINGLE_FILE=0 \
-sMODULARIZE=1 \
-sEXPORT_ES6=0 \
-sALLOW_MEMORY_GROWTH=1 \
Expand Down
4 changes: 3 additions & 1 deletion versions/15/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ ifdef EMSCRIPTEN
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
-sENVIRONMENT="web,node" \
-sENVIRONMENT="web,node,worker" \
-sASSERTIONS=0 \
-sSINGLE_FILE=0 \
-sMODULARIZE=1 \
-sEXPORT_ES6=0 \
-sALLOW_MEMORY_GROWTH=1 \
Expand Down
4 changes: 3 additions & 1 deletion versions/16/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ ifdef EMSCRIPTEN
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
-sENVIRONMENT="web,node" \
-sENVIRONMENT="web,node,worker" \
-sASSERTIONS=0 \
-sSINGLE_FILE=0 \
-sMODULARIZE=1 \
-sEXPORT_ES6=0 \
-sALLOW_MEMORY_GROWTH=1 \
Expand Down
4 changes: 3 additions & 1 deletion versions/17/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ ifdef EMSCRIPTEN
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
-sENVIRONMENT="web,node" \
-sENVIRONMENT="web,node,worker" \
-sASSERTIONS=0 \
-sSINGLE_FILE=0 \
-sMODULARIZE=1 \
-sEXPORT_ES6=0 \
-sALLOW_MEMORY_GROWTH=1 \
Expand Down