Electron and sequelize error: the dialect sqlite is not supported

后端 未结 4 641
情歌与酒
情歌与酒 2021-02-06 03:31

I\'m trying to use sequelize and sqlite with electron in a desktop application but get the following error when running the app via npm start (which runs node

4条回答
  •  天涯浪人
    2021-02-06 04:12

    I know you have sqlite3 installed and working alone but the problem arise when you try to use sqlite3 with electron together. It's because of ABI version mismatch.

    When you put a

    console.log(err); in

    /node_modules/sequelize/lib/dialects/sqlite/connection-manager.js line 21,

    just before throw new Error('Please install sqlite3 package manually'); you will see an error like following:

    { [Error: Cannot find module '/node_modules/sqlite3/lib/binding/node-v44-linux-x64/node_sqlite3.node'] code: 'MODULE_NOT_FOUND' }
    

    However when you check /node_modules/sqlite3/lib/binding/ folder there will be no node-v44-linux-x64 folder but something like node-v11-linux-x64 folder. (Simply renaming the folder won't work.)

    This mismatch occurs because electron uses io.js v3.1.0 internally as it states here and ABI versions of it and your version of nodejs don't match.

    Note that node-vXX is decided via your node's ABI version. Check this url for further info: https://github.com/mapbox/node-pre-gyp/issues/167

    Solution

    The easy way stated here https://github.com/atom/electron/blob/master/docs/tutorial/using-native-node-modules.md#the-easy-way doesn't work as-is with sqlite but you can follow these steps to make it work:

    After installing electron-rebuild via following command

    npm install --save-dev electron-rebuild
    

    go to /node_modules/sqlite3/node_modules/node-pre-gyp/lib/util/abi_crosswalk.js and find your node version, then change node_abi value to 44. Like following:

    "0.12.7": {
      "node_abi": 44,
      "v8": "3.28"
    },
    

    then give ./node_modules/.bin/electron-rebuild command and wait a bit. Then it works.

提交回复
热议问题