better-sqlite3: TypeError: Cannot read property 'indexOf' of undefined when I run my electron app

Hi better-sqlite3

I try to run a fresh install of electron which contain your better library.

in my my process electron file (background.ts) I added those 2 lines :

import Database from 'better-sqlite3'
const db = new Database('foobar.db', { verbose: console.log });

If a just launch the first line I have no problem. But If I launch those 2 lines I have this error when I run my electron app.

` INFO Launching Electron…

App threw an error during load

TypeError: Cannot read property ‘indexOf’ of undefined at Function.getFileName (webpack:///./node_modules/bindings/bindings.js?:178:16) at bindings (webpack:///./node_modules/bindings/bindings.js?:82:48) at eval (webpack:///./node_modules/better-sqlite3/lib/database.js?:9:79) at Object…/node_modules/better-sqlite3/lib/database.js (/Users/xxxx/xxxxx/xxxxxx/dist_electron/index.js:133:1) at webpack_require (/Users/xxxxxx/xxxxx/xxxxx/dist_electron/index.js:20:30) at eval (webpack:///./node_modules/better-sqlite3/lib/index.js?:2:18) at Object…/node_modules/better-sqlite3/lib/index.js (/Users/xxxxxx/xxxxxx/xxxxxxx/dist_electron/index.js:157:1) at webpack_require (/Users/xxxxx/xxxxx/xxxxxx/dist_electron/index.js:20:30) at eval (webpack:///./src/background.ts?:7:72) at Module…/src/background.ts (/Users/xxxxxx/xxxxxx/xxxxxx/dist_electron/index.js:1863:1) `

I electron-rebuild my app without issue…

Do you have an idea or a way to resolve this please ?

Technical information :
Electron : 10.1.5 node : 14.15.0 node-gyp : 7.1.2 TypeScript : 3.9.7

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

project

@darkomenx Hi! Here is my solution.

  1. Create file vue.config.js with the following content.
module.exports = {
    configureWebpack: config => {
        config.externals = {
            'better-sqlite3': 'commonjs better-sqlite3'
        };
    },
    pluginOptions: {
        electronBuilder: {
            externals: [ 'better-sqlite3' ]
        }
    }
}
  1. npm run rebuild

project

@darkomenx Hi! Here is my solution.

  1. Create file vue.config.js with the following content.
module.exports = {
    configureWebpack: config => {
        config.externals = {
            'better-sqlite3': 'commonjs better-sqlite3'
        };
    },
    pluginOptions: {
        electronBuilder: {
            externals: [ 'better-sqlite3' ]
        }
    }
}
  1. npm run rebuild

it really works!!!