sql.js icon indicating copy to clipboard operation
sql.js copied to clipboard

Can't import sql-wasm.wasm

Open vtarelkin opened this issue 3 years ago • 4 comments

I want to make sqlite db and browser work together offline in reactJS. I am using "react": "^17.0.2",

It seems there is a sqljs, sql-js and sql.js existing at the same time. Why do you use - in the name? To confuse?

image

I dare to install new version of it and used this demo https://github.com/sql-js/react-sqljs-demo

And it complains on import string

import sqlWasm from "!!file-loader?name=sql-wasm-[contenthash].wasm!sql.js/dist/sql-wasm.wasm";

src/App.js Line 6:1: Unexpected '!' in '!!file-loader?name=sql-wasm-[contenthash].wasm!sql.js/dist/sql-wasm.wasm'. Do not use import syntax to configure webpack loaders import/no-webpack-loader-syntax

After I delete !! in it it complains on

  useEffect(async () => {
    // sql.js needs to fetch its wasm file, so we cannot immediately instantiate the database
    // without any configuration, initSqlJs will fetch the wasm files directly from the same path as the js
    // see ../craco.config.js
    try {
      const SQL = await initSqlJs({ locateFile: () => sqlWasm });
      setDb(new SQL.Database());
    } catch (err) {
      setError(err);
    }
  }, []);

put async inside useEffect. I just want to extract some data from SQLite DB offline

Maybe you could provide code to work with existing DB on localhost offline with use of react ?

P.S. another approach doesn't work for me either even I put wasm file in the root folder

image

image

vtarelkin avatar Sep 07 '21 20:09 vtarelkin

Hello! Did you have a look at the official react demo? https://github.com/sql-js/react-sqljs-demo

lovasoa avatar Sep 08 '21 12:09 lovasoa

Hello! Did you have a look at the official react demo? https://github.com/sql-js/react-sqljs-demo

Sure, I've mentioned it above. image

and on the other PC there are errors complaining on react-scripts that are not installed.

image

vtarelkin avatar Sep 08 '21 13:09 vtarelkin

Did you install the dependencies with npm install before compiling?

lovasoa avatar Sep 08 '21 14:09 lovasoa

Did you install the dependencies with npm install before compiling?

Sure thing.

npm install npm start and plenty of error went through - I attached them above

vtarelkin avatar Sep 08 '21 15:09 vtarelkin