professional debugger
professional debugger

Reputation: 345

how to install sqlite3 in electron?

So here is what i did, i installed electron and sqlite3 inside my project directory

npm install electron --save-dev
npm install sqlite3

but when i try to run this using npm start it gives me error

var sqlite3 = require('sqlite3').verbose();

this line is inside my main.js where i initialize electron things etc. and it works fine without this line. here's the error i get.

Uncaught Exception:
Error: Cannot find module '/home/touseef/Desktop/Projects/pos/node_modules/sqlite3/lib/binding/electron-v6.0-linux-x64/node_sqlite3.node'
Require stack:
- /home/touseef/Desktop/Projects/pos/node_modules/sqlite3/lib/sqlite3.js
- /home/touseef/Desktop/Projects/pos/main.js
- /home/touseef/Desktop/Projects/pos/node_modules/electron/dist/resources/default_app.asar/main.js
- 
    at Module._resolveFilename (internal/modules/cjs/loader.js:627:15)
    at Function.Module._resolveFilename (/home/touseef/Desktop/Projects/pos/node_modules/electron/dist/resources/electron.asar/common/reset-search-paths.js:41:16)
    at Function.Module._load (internal/modules/cjs/loader.js:531:27)
    at Module.require (internal/modules/cjs/loader.js:685:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/home/touseef/Desktop/Projects/pos/node_modules/sqlite3/lib/sqlite3.js:4:15)
    at Module._compile (internal/modules/cjs/loader.js:786:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)

My node version is 10.16.3 and i'm running Ubuntu.

Upvotes: 3

Views: 4726

Answers (1)

detonationbox0
detonationbox0

Reputation: 125

Just had this issue too. I had to rebuild sqlite3.

Installed electron-rebuild, and added "scripts": { "rebuild": "electron-rebuild -f -w sqlite3" },

to my package.json. Then executed npm run rebuild, and let it rebuild. Got rid of this error for me.

Upvotes: 5

Related Questions