Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
timwis opened this issue Nov 7, 2021 · 5 comments
Open

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

timwis opened this issue Nov 7, 2021 · 5 comments

Comments

@timwis
Copy link

timwis commented Nov 7, 2021

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
Copy link

adv1996 commented Nov 8, 2021

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
Copy link
Author

timwis commented Nov 15, 2021

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
Copy link

steida commented Nov 16, 2021

@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
Copy link

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 😆). 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
Copy link
Contributor

quolpr commented Jul 11, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants