electron-forge-docs icon indicating copy to clipboard operation
electron-forge-docs copied to clipboard

electron-forge use sqlite3 has errors: Uncaught Exception: Error: Cannot find module 'sqlite3'

Open xuhj opened this issue 1 year ago • 4 comments

i follow create an Electron app with Vue and Electron Forge it can be run successfuly for npm run start and npm run make then I also do yarn add sqlite3 and add "const sqlite3 = require('sqlite3').verbose();" in main.js it can be run successfuly for npm run start

but npm run make it show "Uncaught Exception: Error: Cannot find module 'sqlite3'" how to Resolve this issue? I have try delete node_modules but useless Uploading 11.jpg…

xuhj avatar Nov 14 '24 02:11 xuhj

11

xuhj avatar Nov 14 '24 02:11 xuhj

yarn add sqlite3 yarn add --dev electron-rebuild ./node_modules/.bin/electron-rebuild and Configure Electron Forge in your forge.config.js to handle native modules Add a postinstall script in your package.json to automatically rebuild for Electron "scripts": { "postinstall": "electron-rebuild -f -w sqlite3" }

And if issue is resolve then close this issue

Nitish0777 avatar Mar 21 '25 13:03 Nitish0777

I've created an entire repository with instructions on how to reproduce this error: https://github.com/Evilscaught/electron-forge-sqlite3

I've been trying to find a way to upgrade my electron application either through electron-rebuild or electron-forge to the latest version for months and SQLite3 has blocked me from being able to do so every step of the way. I'm beginning to think that SQLite3 is just not compatible with newer versions, and it's time to tear it out, and move on to something else.

Evilscaught avatar Jul 23 '25 02:07 Evilscaught

The night is darkest just before dawn

I've figured out how to include SQLite3 in the production build. Please refer to this commit in the repository I've linked above. I couldn't have done this without @caoxiemeihao and the electron-forge-plugin-dependencies package he published on npm.

Hopefully my repository can serve as nice starting point for anyone that wants to jump in. It includes Sequelize as an ORM on-top of SQLite3.

Evilscaught avatar Jul 24 '25 02:07 Evilscaught