How do I use SQL.js in a React app?
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I am trying to use SQL.js within an existing React app.
I tried using the sql-js NPM package and loading SQL.js like so:
import initSqlJs from "sql.js";
await initSqlJs({
locateFile: (file) => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.6.2/${file}` // this was in an async function
});
and got this error at runtime:
./node_modules/sql.js/dist/sql-wasm.js:94:15
Module not found: Can't resolve 'fs'
I saw the demo repository but can't make heads or tails of it!
Any help would be greatly appreciated.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported initialization in an existing React app using the sql.js package and the locateFile configuration shown. Read the referenced demo repository alongside the runtime error in node_modules/sql.js/dist/sql-wasm.js; the issue is resolved when the app initializes SQL.js without the module-resolution failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, sqlite, wasm
- Domain
- database, frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100