electron-forge better-sqlite3 - TypeError: Cannot open database because the directory does not exist

1.1k Views Asked by At

I have a Typescript + Webpack boilerplate from electron-forge.

I store my data with better-sqlite3. And copy the database file with copy-webpack-plugin like this:

plugins: [
    new CopyPlugin({
      patterns: [
        { from: "src/data/db.db", to: "../data/db.db" }
      ],
    }),
  ],

I then get my data base in my index.ts file like this:

const dbPath = isDevEnv
    ? path.join(app.getAppPath(), "src", "data", "db.db")
    : path.join("resources", "app", ".webpack", "data", "db.db");

const db = new Database(dbPath, { verbose: console.log });

It is working okay when running locally, and also when running npm run make. But once I install or uninstall the app, it errors:

image: A Javascript error occured in the main process

A Javascript error occured in the main process
Uncaught exception:
TypeError: Cannot open database because the directory does not exist

While it errors like this, it installs the app okay on my desktop. It runs and is fetching data from the database. Anyone knows why it errors when installing and uninstalling?

0

There are 0 best solutions below