diff --git a/LOADING_WASM.md b/LOADING_WASM.md new file mode 100644 index 0000000..52462af --- /dev/null +++ b/LOADING_WASM.md @@ -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. \ No newline at end of file diff --git a/README.md b/README.md index 7a2c871..f2285f6 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/full/Makefile b/full/Makefile index 8411c45..0032881 100644 --- a/full/Makefile +++ b/full/Makefile @@ -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 \ diff --git a/templates/Makefile.template b/templates/Makefile.template index 132c90b..422f286 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -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 \ diff --git a/versions/13/Makefile b/versions/13/Makefile index 8fcda8d..4ace118 100644 --- a/versions/13/Makefile +++ b/versions/13/Makefile @@ -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 \ diff --git a/versions/14/Makefile b/versions/14/Makefile index cfacf69..1d9b073 100644 --- a/versions/14/Makefile +++ b/versions/14/Makefile @@ -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 \ diff --git a/versions/15/Makefile b/versions/15/Makefile index f2c0398..6a2ee47 100644 --- a/versions/15/Makefile +++ b/versions/15/Makefile @@ -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 \ diff --git a/versions/16/Makefile b/versions/16/Makefile index 06440cc..6bd9e62 100644 --- a/versions/16/Makefile +++ b/versions/16/Makefile @@ -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 \ diff --git a/versions/17/Makefile b/versions/17/Makefile index e1dfba5..6674f7a 100644 --- a/versions/17/Makefile +++ b/versions/17/Makefile @@ -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 \