Make ElectronJS work with SQLite3
Make ElectronJS work with SQLite3
I write this blog just because I’ve spent quite some time… um hum… I mean days and nights and was having a freaking headache just to make SQLite3 work with ElectronJS. I couldn’t find the solution, neither on Github nor Stackoverflow (**Peace and Love bro!). **I’ve found the solution by myself!
StackOverflow, some friendship never ends….
Sqlite3 has some issues with native modules of ElectronJS, when doing simply:
npm install --save sqlite3
It simply doesn’t work! But you are here because of that I guess or out of curiosity! let’s go quickly to your needs!
QUICK NOTE: Using Mono on Linux (or Mac) is enough, skip the Windows part and jump to step 6.
Steps
- **Run Windows **PowerShell as Administrator and run this:
npm install --global --production windows-build-tools
and wait for it to finish completely, it will take a bit long.
If you are running in some kind of issue:
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
copy and set this as your PATH in your Environment System Variables.
- Double check if all is installed, and the most important part is Visual C++ Build Environment. To do so; download the Visual C++ Build Tools. You will be prompted to download files, just choose: Build Tools for Visual Studio 2017, it can be 2017 or greater depending when you read this post. But for the time being you will find this:
It can be 2017 or greater
- Open and Install, you will find this:
4.** Don’t worry if it is installed or not**, because what we need to verify is that VC++ is checked; to do so **click on Modify Button.** This will shows up:
On the right corner, you will see VC++ 2015V14.00. Just check it! And Click on modify to install it.
-
Execute
npm config set python python2.7
andnpm config set msvs_version 2017
on CMD. -
Just install this package:
npm install –save-dev electron-rebuild
Add these two lines under scripts in your **package.json **
Figure 0 (because programmers counts from zero, remember ?)
- This will simply build native node modules with your app. To do so, write this run:
But make sure you did step 5. It’s important.
npm run rebuild
Afterwards, you can do this below to run your app. It will run Electron flawlessly with your app but it doesn’t end here…
electron .
- Now you will try package your app, and make an executable, but no! Don’t do that yet, you will need to make a file a special**file in which you will integrate it to your Electron Packager, just use this below and call it build.js if you want and place it at the same directory level of package.json:
If you haven’t installed electron-package:
npm install --save-dev electron-packager
And add this to the file:
const packager = require('electron-packager');
const rebuild = require('electron-rebuild');
packager({
dir: './',
overwrite: true,
asar: true,
platform: 'win32',
arch: 'ia32',
prune: true,
out: 'release-builds-folder',
executableName: 'my-app',
icon: 'icon/myicon.ico',
afterCopy: [(buildPath, electronVersion, platform, arch, callback) => {
rebuild.rebuild({ buildPath, electronVersion, arch })
.then(() => callback())
.catch((error) => callback(error));
}],
})
As mentioned in Figure 0, this build.js file needs to be executed to package your app:
npm run package-rebuild
And now, you have SQLite3 working fine with Electron + you can package your app without an issue!
Now feel relieved, dear brothas and sistas !
If you have questions, please feel free to ask, and don’t forget to share ! Stay tuned on busymind101.wordpress.com
**GITHUB FOR ELECTRON-REBUILD: **https://github.com/electron/electron-rebuild