Electron-forge: Error: Please install sqlite3 package manually

Created on 19 Sep 2018  路  6Comments  路  Source: electron-userland/electron-forge

It looks like a very old issue but not I think so.
Here https://github.com/kostysh/electron-sqlite-react a simple app scaffold with:

Then I try to npm start I alwais get a error:

App threw an error during load
Error: Please install sqlite3 package manually

Of course, I have done npx electron-rebuild -f -w sqlite3. Also, I have built sqlite from sources but the result is the same.

My system env:

  • Ubuntu 18.04
  • node.js v10.7.0
  • npm v6.4.1

My forge.config.js:

const path = require('path');
const merge = require('webpack-merge');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const sharedModule = {
    rules: [
        {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: [
                        [
                            '@babel/preset-env',
                            {
                                targets: {
                                    electron: '2.0.9'
                                }
                            }
                        ], 
                        '@babel/preset-react'
                    ]
                }
            }
        },
        {
            test: /\.(png|jpg|gif)$/,
            use: ['url-loader']
        }
    ]
};

module.exports = {
    electronRebuildConfig: {
        // force: true
    },
    plugins: [
        [
            '@electron-forge/plugin-webpack', {
                mainConfig: {
                    entry: {
                        index: [
                            '@babel/polyfill',
                            path.resolve(__dirname, 'src/index.js')
                        ]
                    },
                    module: sharedModule,
                    plugins: [
                        new CopyWebpackPlugin([
                            {
                                from: path.resolve(__dirname, 'src/assets'),
                                to: path.resolve(__dirname, '.webpack/assets')
                            }
                        ])
                    ],
                    output: {
                        filename: '[name].js'
                    }
                },
                renderer: {
                    config: {
                        module: merge.smart({
                            rules: [
                                {
                                    test: /\.css$/,
                                    use: ['style-loader', 'css-loader']
                                },
                                {
                                    test: /\.(svg)$/,
                                    use: ['svg-loader']
                                }
                            ]
                        }, sharedModule),
                        resolve: {
                            extensions: ['.js', '.json'],
                        }
                    },
                    prefixedEntries: process.env.NODE_ENV === 'production' ? [] : ['react-hot-loader/patch'],
                    entryPoints: [
                        {
                            html: path.resolve(__dirname, 'src/renderer/index.html'),
                            js: path.resolve(__dirname, 'src/renderer/index.js'),
                            name: 'main_window'
                        }
                    ]
                }
            }
        ]
    ],
    packagerConfig: {},
    makers: [
        {
            name: '@electron-forge/maker-squirrel',
            config: {
                name: 'pandora-market'
            }
        },
        {
            name: '@electron-forge/maker-zip',
            platforms: [
                'darwin'
            ]
        },
        {
            name: '@electron-forge/maker-deb',
            config: {}
        },
        {
            name: '@electron-forge/maker-rpm',
            config: {}
        }
    ],
    publishers: []
};

electron-forge start output with debug info:

> DEBUG=electron-forge:* npx electron-forge start

WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:async-ora Process Started: Checking your system +0ms
  electron-forge:check-system checking system, create ~/.skip-forge-system-check to stop doing this +0ms
  electron-forge:async-ora Process Succeeded: Checking your system -- after 161ms +161ms
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:async-ora Process Started: Locating Application +0ms
  electron-forge:project-resolver searching for project in: /home/[path-to-the-app]/elsqlite +0ms
  electron-forge:project-resolver electron-forge compatible package.json found in /home/[path-to-the-app]/elsqlite/package.json +4ms
  electron-forge:async-ora Process Succeeded: Locating Application -- after 5ms +5ms
  electron-forge:require-search searching [ '@electron-forge/plugin-webpack',
  '/home/[path-to-the-app]/elsqlite/@electron-forge/plugin-webpack',
  '/home/[path-to-the-app]/elsqlite/node_modules/@electron-forge/plugin-webpack' ] relative to /home/[path-to-the-app]/elsqlite +0ms
  electron-forge:require-search testing @electron-forge/plugin-webpack +2ms
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:plugin:webpack hooking process events +0ms
  electron-forge:async-ora Process Started: Preparing native dependencies +765ms
  electron-forge:async-ora Process Renamed: Preparing native dependencies  -->  Preparing native dependencies: 0 / 1 +226ms
  electron-forge:async-ora Process Renamed: Preparing native dependencies: 0 / 1  -->  Preparing native dependencies: 1 / 1 +3ms
  electron-forge:async-ora Process Succeeded: Preparing native dependencies: 1 / 1 -- after 229ms +0ms
  electron-forge:plugins plugin: "webpack" has taken control of the start command +0ms
  electron-forge:async-ora Process Started: Compiling Main Process Code +0ms
  electron-forge:async-ora Process Succeeded: Compiling Main Process Code -- after 4s +4s
  electron-forge:async-ora Process Started: Launch Dev Servers +1ms
  electron-forge:async-ora Process Succeeded: Launch Dev Servers -- after 30ms +30ms
  electron-forge:async-ora Process Started: Compiling Preload Scripts +0ms
  electron-forge:async-ora Process Succeeded: Compiling Preload Scripts -- after 1ms +1ms
  electron-forge:async-ora Process Started: Launching Application +4s
  electron-forge:async-ora Process Succeeded: Launching Application -- after 13ms +13ms


Webpack Output Available: http://localhost:9000

  electron-forge:plugin:webpack hooking electron process exit +4s
App threw an error during load
Error: Please install sqlite3 package manually
    at new ConnectionManager (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:114110:15)
    at new SqliteDialect (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:114491:30)
    at new Sequelize (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:123593:20)
    at Module../src/db.js (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:150060:12)
    at __webpack_require__ (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:21:30)
    at Module../src/index.js (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:150099:61)
    at __webpack_require__ (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:21:30)
    at Object.0 (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:150166:18)
    at __webpack_require__ (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:21:30)
    at /home/[path-to-the-app]/elsqlite/.webpack/main/index.js:85:18
    at Object.<anonymous> (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:88:10)
    at Object.<anonymous> (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:150415:3)
    at Module._compile (module.js:642:30)
    at Object.Module._extensions..js (module.js:653:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at loadApplicationPackage (/home/[path-to-the-app]/elsqlite/node_modules/electron/dist/resources/default_app.asar/main.js:287:12)
    at Object.<anonymous> (/home/[path-to-the-app]/elsqlite/node_modules/electron/dist/resources/default_app.asar/main.js:328:5)
    at Object.<anonymous> (/home/[path-to-the-app]/elsqlite/node_modules/electron/dist/resources/default_app.asar/main.js:365:3)
    at Module._compile (module.js:642:30)
    at Object.Module._extensions..js (module.js:653:10)
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Please install sqlite3 package manually
    at new ConnectionManager (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:114110:15)
    at new SqliteDialect (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:114491:30)
    at new Sequelize (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:123593:20)
    at Module../src/db.js (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:150060:12)
    at __webpack_require__ (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:21:30)
    at Module../src/index.js (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:150099:61)
    at __webpack_require__ (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:21:30)
    at Object.0 (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:150166:18)
    at __webpack_require__ (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:21:30)
    at /home/[path-to-the-app]/elsqlite/.webpack/main/index.js:85:18
    at Object.<anonymous> (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:88:10)
    at Object.<anonymous> (/home/[path-to-the-app]/elsqlite/.webpack/main/index.js:150415:3)
    at Module._compile (module.js:642:30)
    at Object.Module._extensions..js (module.js:653:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:504:12)
    at Function.Module._load (module.js:496:3)
    at loadApplicationPackage (/home/[path-to-the-app]/elsqlite/node_modules/electron/dist/resources/default_app.asar/main.js:287:12)
    at Object.<anonymous> (/home/[path-to-the-app]/elsqlite/node_modules/electron/dist/resources/default_app.asar/main.js:328:5)
    at Object.<anonymous> (/home/[path-to-the-app]/elsqlite/node_modules/electron/dist/resources/default_app.asar/main.js:365:3)
    at Module._compile (module.js:642:30)
    at Object.Module._extensions..js (module.js:653:10)
webpack built 7fca1094a6ea0f988ecf in 1313ms
^C  electron-forge:plugin:webpack handling process exit with: { exit: true } +2s
undefined
  electron-forge:plugin:webpack handling process exit with: { cleanup: true } +2ms
  electron-forge:plugin:webpack cleaning webpack watcher +0ms
  electron-forge:plugin:webpack cleaning http server +14ms
  electron-forge:plugin:webpack stopping logger +0ms

Test case

Most helpful comment

According to my previous comment I have found a solution. I have added sqlite3 module to the external config and thats solved the problem. For now, my mainConfig is looks like:

mainConfig: {
    entry: {
        index: [
            '@babel/polyfill',
            path.resolve(__dirname, 'src/index.js')
        ]
    },
    module: sharedModule,
    plugins: [
        new CopyWebpackPlugin([
            {
                from: path.resolve(__dirname, 'src/assets'),
                to: path.resolve(__dirname, '.webpack/assets')
            }
        ])
    ],
    output: {
        filename: '[name].js'
    },
    externals: ['sqlite3']
},

So, thats was not a error in the electron-forge and issue can be closed.

All 6 comments

@kostysh I think you need to configure a loader for native modules. native-loader

--> https://github.com/webpack-contrib/node-loader

@MarshallOfSound native-loader cannot helping. all the same ((

I have figured out that the source of trouble is in the way of how defined a path to the package.json of sqlite3 module.

// ./node_modules/sqlite3/lib/sqlite3.js
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));

Here the module is waiting what __dirname will be pointing to the module directory but at the moment of starting of electron app __dirname is pointing to app directory, not to the module.

According to my previous comment I have found a solution. I have added sqlite3 module to the external config and thats solved the problem. For now, my mainConfig is looks like:

mainConfig: {
    entry: {
        index: [
            '@babel/polyfill',
            path.resolve(__dirname, 'src/index.js')
        ]
    },
    module: sharedModule,
    plugins: [
        new CopyWebpackPlugin([
            {
                from: path.resolve(__dirname, 'src/assets'),
                to: path.resolve(__dirname, '.webpack/assets')
            }
        ])
    ],
    output: {
        filename: '[name].js'
    },
    externals: ['sqlite3']
},

So, thats was not a error in the electron-forge and issue can be closed.

@kostysh having the sqlite3 (better-sqlite3 in my case) as externals does work for the development process. But when I go ahead with packaging, the module is not to be found in the build.

If anyone still facing issue, try using better-sqlite3 instead of sqlite3.
Follow regular steps and it should work.

Better sqlite3 7.0.1 solves this issue of binding native module which existed earlier.
Please have a look.

Was this page helpful?
0 / 5 - 0 ratings