jlongster / absurd-sql

sqlite3 in ur indexeddb (hopefully a better backend soon)
MIT License
4.15k stars 101 forks source link

Where do I get sql-wasm.wasm ? #46

Open timwis opened 2 years ago

timwis commented 2 years ago

Hi! Really excited by this project. I'm trying it out locally, using the directions in the readme, and my browser's making a request for /js/sql-wasm.wasm which throws a 404 as it doesn't exist. Not sure what's calling it, or where it's supposed to be. Any suggestions?

I see it as a static file in the example repo, but the readme doesn't mention it 🤔

adv1996 commented 2 years ago

Hey @timwis I just downloaded the .wasm file from the examples folder.

https://github.com/jlongster/absurd-sql/blob/master/src/examples/sql-wasm.wasm

In my react application where I'm testing this library I put it in the public/wasm/bin folder and it works. When I initialize it with initSQLJs it looks like this

SQL = await initSqlJs({ locateFile: file => `/wasm/bin/${file}` });

timwis commented 2 years ago

Thanks, but:

  1. The documentation doesn't mention that as a installation step
  2. I can't see the source of it, so I don't know if it's specific to that example, or what it does in the first place
  3. Using it from the npm module would be preferable to 'vendoring' it (adding it to my source control)
  4. My browser was making requests for /js/sql-wasm.wasm, even though that my code said locateFile: file => file
steida commented 2 years ago

@timwis

As for 1., check https://github.com/jlongster/absurd-example-project, that file is there. As for 4., try to add /

locateFile: (file: string) => `/${file}`
smithbm2316 commented 2 years ago

I just ran into this problem myself, which had been causing me quite a headache for several hours today. Didn't realize for a while that the problem was that my browser couldn't find sql-wasm.wasm, thought it was something wrong with my service worker setup for a while (apparently learning how to use service workers and absurd-sql for the first time might have been a bigger task than I anticipated :laughing:). If you check your node_modules and go into -> @jlongster -> sql.js -> dist folder, the file should be there! I just went ahead and copied that file to my build tool's directory that serves static assets (for me with vite and vite-plugin-pwa it's /public) and it seems to be working properly for me now! Hope that helps for anyone else who might have this issue

quolpr commented 2 years ago

Overall, it's not a good practice to copy wasm file to your public dir, then you will lose ability to receive updates. It's better to import from lib. Here how you can do with CRA:

import sqlWasmUrl from "@jlongster/sql.js/dist/sql-wasm.wasm";

Or with vite:

import sqlWasmUrl from "@trong-orm/sql.js/dist/sql-wasm.wasm?url";

Also, this might help you https://trong-orm.netlify.app/core/usage https://trong-orm.netlify.app/backends/web (it's an abstraction layer, that makes it easier to use absurd-sql. There is also CRA and vite repo example)