xaander1
xaander1

Reputation: 1160

How do i make electron rebuild work so that i can use sqlite3?

I am trying to create an app that uses sqlite3 however in order for it to work i need to install and run electron-rebuild while knex act's as my middleware.

i have managed to install all the npm packages knex, sqlite3 and electron-rebuild using the following commands:

npm install electron-rebuild --save-dev

npm install sqlite3 knex

in my package.json scripts i have include:

  "scripts": {
    "rebuild": "electron-rebuild -f -w sqlite3",
    "start": "electron .",
    "test": "echo \"Error: no test specified\" && exit 1"
  }, 

However when i run: npm run rebuild I get:

> [email protected] rebuild /home/alexander/Desktop/tarik
> electron-rebuild -f -w sqlite3


An unhandled error occurred inside electron-rebuild
Unable to find electron-prebuilt's version number, either install it or specify an explicit version

Error: Unable to find electron-prebuilt's version number, either install it or specify an explicit version
    at Object.<anonymous> (/home/alexander/Desktop/tarik/node_modules/electron-rebuild/lib/src/cli.js:81:19)
    at Generator.next (<anonymous>)
    at /home/alexander/Desktop/tarik/node_modules/electron-rebuild/lib/src/cli.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/alexander/Desktop/tarik/node_modules/electron-rebuild/lib/src/cli.js:4:12)
    at /home/alexander/Desktop/tarik/node_modules/electron-rebuild/lib/src/cli.js:70:8
    at Object.<anonymous> (/home/alexander/Desktop/tarik/node_modules/electron-rebuild/lib/src/cli.js:146:4)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! [email protected] rebuild: `electron-rebuild -f -w sqlite3`
npm ERR! Exit status 255
npm ERR! 
npm ERR! Failed at the [email protected] rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/alexander/.npm/_logs/2019-09-01T12_36_46_896Z-debug.log

i am using ubuntu18.04

Upvotes: 0

Views: 2288

Answers (1)

xaander1
xaander1

Reputation: 1160

Figured out how to fix this to help someone else in future here is what i did:

  • You need to install electron in your current project. I was using globally installed electron...also don't forget to save the dependency. If not saved you'll get errors when rebuilding.
  • i was running the electron-rebuild wrongly to run electron rebuild:

On macOS and linux

Every time you run "npm install", run this:

   ./node_modules/.bin/electron-rebuild

On Windows

On Windows if you have trouble, try:

 .\node_modules\.bin\electron-rebuild.cmd

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

Upvotes: 1

Related Questions