Using Sequelize with sqlite3 inside an Electron app

Introduction

A few months ago I ran into some problems when I tried to use Sequelize with sqlite3 inside an Electron app. Even though I installed everything properly, I was getting this error:

Uncaught Error: The dialect sqlite is not supported. (Error: Please install sqlite3 package manually)

I was able to fix this using this website but it appears to be down now. I decided to write down the method here and also adding a bit more details on how to solve the problem.

Solution

  • Go to `node_modules/sequelize/lib/dialects/connection-manager.js` and identify the `MODULE_NOT_FOUND` error code. Log the error with a `console.log(err)` before the error is thrown.
  • Run the application and you will get a more detailed error:

`{ Error: Cannot find module ‘C:\Users\Razvan\Documents\devStuff\work\app\server\node_modules\sqlite3\lib\binding\electron-v1.3-win32-x64\node_sqlite3.node’`

  • Note the `electron-v1.3-win32-x64`. You might have something different depending on the electron version you installed
  • `cd node_modules/sqlite3` and then run the following:
npm run prepublishOnly
node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.3-win32-x64
node-gyp rebuild --target=1.3.5 --arch=x64 --target_platform=win32 --dist-url=https://atom.io/download/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.3-win32-x64
  • ` — module_path` replace with what you got from the MODULE_NOT_FOUND error
  • ` — target_platform` win32, darwin or linux
  • ` — arch` x64 or ia32
  • ` — target` the version of electron you are using

If there are issues on Windows about MSB4019, check this issue https://github.com/brianmcd/contextify/issues/96

That’s all

By following the steps above I managed to make the configuration work on Windows and Mac. Hopefully this solves the problem for you too.

If you still encounter the problem, check this post on stackoverflow. It offers multiple approaches.


Originally published at Răzvan Ilin.