1

Consider this example created by using the following steps:

git clone --depth=1 https://github.com/electron-react-boilerplate/electron-react-boilerplate.git better-sqlite3-test
cd better-sqlite3-test
yarn
cd ./release/app
yarn add better-sqlite3
cd ../..
yarn add -D @types/better-sqlite3

Now, as soon as I start using the database.js like this:

class B3SqliteDB {
  constructor() {
    let db = null;
  }

  startDB = () => {
    const Database = require('better-sqlite3');
    this.db = new Database('upStore.db', { verbose: console.log });

    const createTable =
      "CREATE TABLE IF NOT EXISTS newTable ('id'  VARCHAR(10) NOT NULL, 'name'  VARCHAR(50) NOT NULL);";

    this.db.exec(createTable);
  };
}
export default new B3SqliteDB;

I am getting the error:

Uncaught TypeError: Database is not a constructor
    at B3SqliteDB.startDB (renderer.dev.js:65346)
    at renderer.dev.js:65285

Can someone please help to figure this out! TYA

Firdous Ahmad
  • 49
  • 1
  • 8

1 Answers1

3

This worked for me

  • Downgrade electron to 13.6
  • Install better-sqlite3 in root
  • Rebuild the package
  • Test

yarn remove electron
yarn add electron@13.6.1
yarn add better-sqlite3; 
cd node_modules/better-sqlite3; 
../.bin/electron-rebuild
cd ../..
npm run start

enter image description here

Note

  • You can try other desktop options (Electron Alternatives) that support integration ReactJS | VueJS just fine
  1. Wails (Golang) https://github.com/wailsapp/wails
  2. Lorka (Golang) https://github.com/zserge/lorca
  3. Tauri (Rust) https://github.com/tauri-apps/tauri
  4. Flutter Desktop (Dart) https://flutter.dev/desktop
  • What I love is that the app size is just 10 - 20 times smaller than a sample Hello World Electron App.