You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron配置SQLite3报错"please install sqlite3 package manually"的解决方法

Fixing "please install sqlite3 package manually" Error in Electron Apps

I’ve been right where you are—spent 4 full workdays fighting this exact issue with SQLite refusing to play nice with Electron, even after reinstalling dependencies over and over. Most online solutions skipped critical steps, so I put together this fully tested, step-by-step guide to save you the frustration.

Step 1: Start with a Clean Slate

First, we’ll wipe out any conflicting installs to avoid leftover issues:

  • Uninstall the existing sqlite3 package: npm uninstall sqlite3
  • Clear your npm cache: npm cache clean --force
  • Delete the node_modules folder and package-lock.json (or yarn.lock if you use Yarn)

Step 2: Install sqlite3 with Electron-Specific Build Flags

The root problem is that sqlite3 needs to be built for Electron’s unique Node.js runtime. Use these commands to install it correctly:

  • Install electron-rebuild (a must-have for rebuilding native modules for Electron) as a dev dependency:
    npm install --save-dev electron-rebuild
  • Install sqlite3 again, replacing your-electron-version with the actual version listed in your package.json (e.g., 28.0.0):
    npm install sqlite3 --build-from-source --runtime=electron --target=your-electron-version --dist-url=https://electronjs.org/headers

Step 3: Run Electron Rebuild

This step ensures the sqlite3 module is fully compatible with your Electron instance:

  • Add a convenience script to your package.json (optional but recommended):
    "scripts": {
      "rebuild": "electron-rebuild -f -w sqlite3"
    }
    
  • Execute the rebuild: npm run rebuild

Step 4: Verify the Fix

Test with a simple snippet in your Electron main process to confirm no errors pop up:

const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database(':memory:');

db.serialize(() => {
  db.run("CREATE TABLE lorem (info TEXT)");
  const stmt = db.prepare("INSERT INTO lorem VALUES (?)");
  for (let i = 0; i < 10; i++) {
    stmt.run(`Ipsum ${i}`);
  }
  stmt.finalize();

  db.each("SELECT rowid AS id, info FROM lorem", (err, row) => {
    if (err) console.error(err);
    console.log(`${row.id}: ${row.info}`);
  });
});

db.close();

If you see the log entries without the dreaded "please install sqlite3 package manually" error, you’re all set!

Bonus Troubleshooting Tips

  • If using Electron Forge or Electron Builder, ensure sqlite3 is included in your bundled dependencies. For Electron Builder, add this to your package.json:
    "build": {
      "extraResources": [
        {
          "from": "node_modules/sqlite3/lib/binding/",
          "to": "./node_modules/sqlite3/lib/binding/",
          "filter": ["**/*"]
        }
      ]
    }
    
  • Double-check that your Node.js version matches the one compatible with your Electron version (you can find this info in Electron’s release notes).

内容的提问来源于stack exchange,提问作者UFFAN AHMED

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:20:56