Description
Hi, I'm trying to use sqlite-wasm in both browser and node environment. The node environment is used for unit test. I don't expect OPFS to work so I switched to in-memory DB instead. When I run the sample code, it looks like the library is still expecting browser environment and throws an error:
Loading and initializing SQLite3 module...
Process exited with code 1
Exception loading sqlite3 module: TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11457:11) {cause: Error: not implemented... yet...
at makeNe…or (node:internal/deps/undici/undici:6802:35)…, stack: 'TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11457:11)', message: 'fetch failed'}
Uncaught TypeError TypeError: fetch failed
at fetch (internal/deps/undici/undici:11457:11)
Here is the screenshot of the setup. My node version is 20.0.0
I noticed that 3.42 ships with a sqlite-node.mjs
file. So I hard coded the import path to it:
And got a self
error seemingly related to #3
sqlite3 bootstrap initializer threw: ReferenceError: self is not defined
at StructBinderFactory (/workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:7859:20)
at /workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:9321:43
at /workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:6686:13
at Array.forEach (<anonymous>)
at sqlite3ApiBootstrap (/workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:6685:44)
at /workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:13243:32
at callRuntimeCallbacks (/workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:681:26)
at postRun (/workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:459:7)
at doRun (/workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:5642:9)
at run (file:///workspaces/tinykb/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-node.mjs:5654:9) {stack: 'ReferenceError: self is not defined
at St…m/sqlite-wasm/jswasm/sqlite3-node.mjs:5654:9)', message: 'self is not defined'}
I understand if there is no official support for node.js runtime due to lack of dev resource. I'd still like to propose such a feature as it allows test driven development. In the js ecosystem, most unit test setups require node.js based runtime. Also, wasm is supposed to be the universal binary format that is agnostic of browser vs. node.js (or even deno), so it would be amazing for sqlite to work anywhere wasm runs.