How to use sqlite3 module with electron?

前端 未结 10 1336
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 01:43

I want to develop desktop app using electron that uses sqlite3 package installed via npm with the command

npm install --save sqlite3

but it

相关标签:
10条回答
  • 2020-11-28 02:35

    I encounter this error too. Here is how i solve it: npm install --save-dev electron-rebuild then: ./node_modules/.bin/electron-rebuild

    from: https://electronjs.org/docs/tutorial/using-native-node-modules

    ps: While it's on rebuilding, don't use npm startto lanch the electron app. Otherwise the rebuild process would fail.

    0 讨论(0)
  • 2020-11-28 02:39

    It works for me in version 3 and 4, unfortunately NOT version 5. See the sqlite3 documentation for details: https://www.npmjs.com/package/sqlite3#custom-builds-and-electron or otherwise run the following line: npm install sqlite3 --runtime=electron --target=4.0.0 --dist-url=https://atom.io/download/electron

    0 讨论(0)
  • 2020-11-28 02:41

    A simpler solution:

    1. Install electron-rebuild npm i electron-rebuild --save-dev
    2. Launch electron-rebuild ./node_modules/.bin/electron-rebuild (or .\node_modules\.bin\electron-rebuild.cmd on windows)
    3. Go to "node_modules/sqlite3/lib/binding/" and rename the folder "electron-v0.36-darwin-x64" to "node-v47-darwin-x64"

    PS: v47 is my version, be careful to choose the good one (in your case v45)

    0 讨论(0)
  • 2020-11-28 02:43

    By far the easiest way to use SQLite with electron is with electron-builder.

    First, add a postinstall step in your package.json:

    "scripts": {
       "postinstall": "install-app-deps"
       ...
    }
    

    and then install the necessary dependencies and build:

    npm install --save-dev electron-builder
    npm install --save sqlite3
    npm run postinstall
    

    electron-builder will build the native module for your platform, with the correct name for the Electron binding; and you can then require it in code as normal.

    See my github repo and blog post - it took me quite a while to figure this out too.

    0 讨论(0)
提交回复
热议问题