top of page
  • Writer's pictureسميرالجيبان

Setting Up SQLite with Electron on Windows

During a latest development I have been doing with my team in which we were using Electron to develop a multi-platform Desktop application, we needed to use a database. After some analysis we decided to go with SQLite as we saw it perfect for the job.

It turned out to be a hard task to set up the database to work with Electron out of the box. It was not really hard but there is really not enough documentation and online resources to solve the faced issues. I decided to put this here to help people.

As the title implies, this issue is relevant to you if you developing on a Windows box. We were specifically using Windows 10.

The Electron Sample

I am going to start with the sample example provided by Electron in their website. You can clone it and run it from the following URL:

Specifically, the following section (this is an image from their website on the setup of the sample) has the instructions to do that:

The only requirement for the sample above to run is to have Node installed.

You can use any sample you like or write but I thought that this would be easier to start with.

Installing SQLite

Once you have the above sample running, let us now install SQLite:

Using SQLite inside the Electron Sample

I wrote the following code just to make use of SQLite inside the Electron sample. For the sake of this example, I just put this code at the top of the main.js file of the sample:

Now, if you try to run the application, you will get the following error:

This is because SQLite is a native Node module and it has not been built for Electron targeting the platform I am using. If this was a plain Node app then this error would have not been raised because the native module (SQLite) has been downloaded with npm install already. Also, the downloaded native module is unlikely to work with Electron as Electron is using different V8 than Node in most cases.

You can solve this issue by rebuilding the SQLite native module. You can find multiple ways to do that here

I am going to use the 'electron-rebuild' option.

Rebuilding SQLite for Electron

Let us start by installing the electron-rebuild package:

Now, let us rebuild the module by running the following command (taken from


But although you followed everything in the above URL for building the module using electron-rebuild, you are still faced with an error. This is where the part where documentation fall short. Here is the output of the command:

Actually, the error is longer that than but what matters is shown in the snapshot. The rebuild process requires Python and not any Python but version 2.7.x.

Install Python 2.7 from the following URL (at the time of writing) Just make sure to pick a 2.7.x version and not a 3.x version. After that, make sure to have python.exe is part of the PATH environment variable. It should be done automatically by the installer but confirm that.

Re-run the above rebuild command after installing Python and you could encounter the following error:

The message is much longer that than but this is a zoom on the error. It is complaining that Microsoft Build Tools v140 is not there. This is the C++ tools required to build the native module that came with Microsoft Visual Studio 2015. I am assuming that you are by now using Visual Studio 2017.

You will have to install those tools from Microsoft Visual Studio Installer. Run the Installer and check the following option and install:

If you are not using Visual Studio already then install the Community (free) version for that purpose and make sure you select the option above.

After the installation of the tool, re-run the above command in a fresh Command Prompt to make sure you got the latest updated PATH environment variable and this time…

It works! Rebuild is complete. What a journey.

Running the App Successfully

Let us try now running the Electron sample app:

It worked now showing the message that we are connected to the in-memory Db using SQLite.

The take away from this blog article is that when you are developing using Electron and SQLite on Windows, you will need to have the SQLite native module built for that. You can use the electron-rebuild package to do that but you still need to have additional prerequisite for this to work. Those are Python 2.7 and MS Build Tools V140. You may be lucky having them installed and not face any issue but from experience didn't see this happening with many developers.


Commenting has been turned off.

مدون الجيبان

bottom of page