Comments (7)
@rossjs I'm facing the same problem. This will be a issue with every js bundler trying to resolve the module sql.js/dist/sql-wasm.js
for a frontend application.
My current workaround is to keep the js file in index.html and out of the bundler π
<script src="/assets/sql-js/sql-wasm.js"></script>
in a typescript frontend application it could be used like this:
(window as any).initSqlJs({
// Required to load the wasm binary asynchronously.
locateFile: () => '/assets/sql-js/sql-wasm.wasm'
}).then((instance: any) => {
(window as any).SQL = instance;
});
Here is a open PR for this issue:
#539
from sql.js.
I had a similar issue. The problem is how you invoke the library.
Instead of doing,
const initSqlJs = require('sql.js');
Do the following:
// or if you are in a browser:
const initSqlJs = window.initSqlJs;
That solved my issue.
from sql.js.
I actually ended up switching to use Vite as my bundler due to this issue and found that works. Still learning the differences between it and CRA, but it's been relatively painless so far. I'm also using the sql.js hosted wasm file for now.
import initSqlJs from 'sql.js';
const initDb = async () => {
const SQL = await initSqlJs({ locateFile: (file) => `https://sql.js.org/dist/${file}` });
return new SQL.Database();
};
// vite.config.js
import { defineConfig } from 'vite';
import wasm from 'vite-plugin-wasm';
import react from '@vitejs/plugin-react';
import eslint from 'vite-plugin-eslint';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
wasm(),
react({
// hot reload doesn't work without this Β―\_(γ)_/Β―
include: '**/*.jsx',
}),
eslint(),
],
// vite doesn't expose process.env and sql.js expects it
define: {
'process.env': {},
},
});
from sql.js.
Thanks for sharing @rossjs ! vite.js looks really nice π unfortunately, I canβt exchange the bundler in near future (and I think many developers are in the same situation) β¦ so I keep having high hopes that this library will become compatible with webpack again some day :)
from sql.js.
Hey are you using esbuild
? if yes, you can mark fs
and path
as external module(see https://esbuild.github.io/api/#external ),afterwards esbuild will ignore this error and that require
will never run in a browser.
from sql.js.
you need to add fallback in resolve object in react script/config/webpack-config.js in node_module
fallback: {fs:false },
from sql.js.
It sounds like there's some some paths forward by updating the webpack config or switching to vite. It also seems like CRA is only getting the absolute bare minimum of support these days and isn't a great path forward long term so I'm going to go ahead and close out this issue. Feel free to open up a new one if you think it warrants it.
Thanks for all the suggestions everyone!
from sql.js.
Related Issues (20)
- New release with recent sqlite version HOT 2
- Memory issues in 1.9.0 HOT 39
- limit keyword is ignored when using parameters. HOT 6
- datetime function 'subsec', 'subsecond' modifier cause null return value. HOT 1
- failed to asynchronously prepare wasm: both async and sync fetching of the wasm failed
- Binding not working with json field HOT 4
- out of memory HOT 9
- Wasi HOT 3
- The PROCEDURE keyword is not supported when running on the Online SQL interpreter." HOT 1
- Getting an error on Memory access out of bounds when trying to run db.exec with a large query string
- Create a visualizer for SQL HOT 1
- Bug: Out of memory if reloading the page excessively HOT 4
- Mising types preventing compilation HOT 2
- What are the tradeoffs between sql.js and IndexedDB? HOT 3
- Can I import Javascript objects (and/or JSON) directly into a table? HOT 3
- sqlite vesrion HOT 1
- file is not a database. HOT 2
- file is not a database. HOT 1
- stmt.getAsObject() gives empty object in the latest release (v1.10.3) HOT 9
- Performance issues on Firefox with debugger open
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sql.js.