sql-js / sql.js

A javascript library to run SQLite on the web.
http://sql.js.org
Other
12.59k stars 1.06k forks source link

"fetch" api included in NodeJS v18 brokes sql.js #528

Open erayhanoglu opened 2 years ago

erayhanoglu commented 2 years ago

NodeJS 18 includes experiential support for the "fetch" api. This is causing sql.js not to work properly after Node v18. Because it checks if there is an global "fetch" funcion exists. If so it tries to fetch the wasm file.

sql-wasm.js .... "function"!=typeof fetch?c(b):fetch(P,{credentials:"same-origin"}) .....

This check is invalid for NodeJS v18.

lovasoa commented 2 years ago

This is a good catch, but this is an emscripten issue, isn't it ? All we can do is update to a more recent emscripten when they fix the bug, right ?

johncardiologs commented 2 years ago

I'm having a perhaps related strange error:

Error: Aborted(RuntimeError: Aborted(Error: ENOENT: no such file or directory, open 'http:/localhost:8000/sql-wasm.wasm'). Build with -sASSERTIONS for more info.). Build with -sASSERTIONS for more info.
 ❯ E node_modules/sql.js/dist/sql-wasm.js:101:154
 ❯ node_modules/sql.js/dist/sql-wasm.js:158:425

Trying to serve a custom sql-wasm.wasm file for myself. Getting these errors suddenly :grimacing: At one point I did npm i and it said "changed 1 packaged" and then things started working again? But then when I reinstalled all my packages, on node version 18.8.0, it gave me this error. I've triple checked the url I'm passing in, and it is (correctly) http://localhost:8000/sql-wasm.wasm (with both slashes, not one). :shrug:

EDIT: using sql.js version 1.7.0 fixed this for me. Also, staying with node version 18 rather than 16.

darichey commented 1 year ago

Can confirm this is fixed. Works for me on sql.js 1.8.0 and Node 19.2.0