Thalinda Bandara
Thalinda Bandara

Reputation: 1079

Cannot find module node_sqlite3.node when I try to import

For my Electron application using sqlite3 I developed a module. I am trying to import that into main.js but it's throwing an error from require:

Cannot find module 'E:\CSV-CONVERTOR\node_modules\sqlite3\lib\binding\napi-v6-win32-x64\node_sqlite3.node'

I tried many solutions (1, 2, 3 and 4) but they're giving the same error:

enter image description here

var sqlite3 = require('sqlite3').verbose(); works. node process.js is working but when I run this from main.js I get this error.

Upvotes: 3

Views: 8519

Answers (2)

Thalinda Bandara
Thalinda Bandara

Reputation: 1079

Run npm install --save-dev electron-rebuild then install sqlite3: npm install --save sqlite3.

Add this line to package.json, then run "rebuild": "electron-rebuild -f -w sqlite3". You will get a node in "/.../node_modules/sqlite3/lib/binding/electron-v1.4-darwin-x64/node_sqlite3.node".

I had to change the folder name from "electron-{your-version}-darwin-x64" to the actual version. From "node_modules/sqlite3/lib/binding/" rename according to you version (mine was napi-v6-win32-x64).

Upvotes: 3

kirogasa
kirogasa

Reputation: 949

For some old versions of Electron (for mac, win, lin), you can get the prebuild binaries from the package sqlite3-offline.

list of directory of package sqlite3-offline

Upvotes: 0

Related Questions