better-sqlite3 in Electron 28: 'compiled against a different Node.js version using NODE_MODULE_VERSION 115. This version of Node.js requires NODE_MODULE_VERSION 119' (and the reverse after rebuild)
Fix: rebuild native modules against Electron's ABI after every npm install: npx @electron/rebuild -f -w better-sqlite3 (add it as a postinstall script). The old electron-rebuild package is deprecated in favour of @electron/rebuild with the same CLI. npm install builds or downloads better-sqlite3 for the system Node (Node 20 = NODE_MODULE_VERSION 115), but Electron 28.3.3 embeds its own Node with ABI 119. So the main process throws "The module '.../better_sqlite3.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 115. This version of Node.js requires NODE_MODULE_VERSION 119. Please try re-compiling or re-installing the module". Check both numbers with node -p process.versions.modules and ELECTRON_RUN_AS_NODE=1 npx electron -e "console.log(process.versions.modules)". Every Electron major has its own ABI, so do not copy a number from another project. The catch: after the Electron rebuild, plain Node can no longer load the module, and the error flips to 'compiled against ... NODE_MODULE_VERSION 119. This version of Node.js requires NODE_MODULE_VERSION 115'. That breaks Jest/Vitest unit tests, seed scripts and migrations run with node. Run those through Electron (ELECTRON_RUN_AS_NODE=1 electron script.js), or run npm rebuild better-sqlite3 before Node-only jobs and @electron/rebuild before packaging. better-sqlite3 opens the .node file lazily, so require() can succeed and the error appears only at new Database(). Reproduced both directions in a node:20-bookworm container with electron 28.3.3.