Electron + SQLite plugin error after successful build

Hello!
I have an issue:

Created an app on electron, two simple pages, build ok, pack ok, running without issues on windows and linux (ubuntu).

Now:
Added sqlite, some query/insert, works on browser, tried to build, found some errors:

Then after doing all that suggested by Keith, the app is now created, but the app is broken:


Uncaught (in promise) Error: "CapacitorSQLite" plugin is not implemented on electron
    at runtime.js:69:23
    at runtime.js:76:32
    at async Promise.all (capacitor-electron://-/index 0)
    at async Promise.all (capacitor-electron://-/index 0)
    at async Promise.all (capacitor-electron://-/index 0)

Here is some info:
Package.json

{
  "name": "wappler_desktop_app",
  "version": "1.0.0",
  "dependencies": {
    "@capacitor/core": "^7.0.1",
    "@capacitor-community/electron": "*",
    "@capacitor-community/sqlite": "^7.0.0",
    "jeep-sqlite": "^2.8.0",
    "sql.js": "1.11.0"
  },
  "devDependencies": {
    "@capacitor/cli": "^7.0.0",
    "@types/minimatch": "^6.0.0"
  }
}

Capacitor.json:

{
  "appId": "com.example.app",
  "appName": "helloworld",
  "webDir": "www",
  "bundledWebRuntime": true,
  "plugins": {
    "CapacitorSQLite": {
      "electronWindowsLocation": "CapacitorDatabases",
      "electronMacLocation": "CapacitorDatabases",
      "electronLinuxLocation": "CapacitorDatabases"
    }
  }
}

I think I'm missing some step here :frowning:
Anyone has an idea to try?
Thanks in advance


Uncle Chat GipItEE...


That error means the CapacitorSQLite plugin isn’t implemented for the Electron platform in your current setup.

The Capacitor SQLite plugin (@capacitor-community/sqlite) only has implementations for iOS, Android, and Web (via jeep-sqlite in the browser). For Electron, you have to add the specific Electron plugin package and configure it.

Here’s how to fix it:


:white_check_mark: Steps to Enable SQLite in Electron

  1. Install the Electron version of the plugin
npm install @capacitor-community/electron
npm install @capacitor-community/sqlite
  1. Add the Electron platform (if not already added)
npx cap add @capacitor-community/electron

This generates an Electron app in electron/.
3. Register the SQLite plugin in Electron
In your electron/src/index.ts (or index.js depending on setup), you need to register the SQLite plugin manually:

import { app } from 'electron';
import { createCapacitorElectronApp } from '@capacitor-community/electron';
import { CapacitorSQLiteElectron } from '@capacitor-community/sqlite';

const capacitorApp = createCapacitorElectronApp({
  mainWindow: {
    // your config
  },
  plugins: {
    CapacitorSQLite: {
      electron: CapacitorSQLiteElectron,
    },
  },
});

app.whenReady().then(() => {
  capacitorApp.init();
});
  1. Rebuild the Electron app
npm run build
npx cap sync @capacitor-community/electron
npm run electron:start

:warning: Common Gotchas

  • If you only need SQLite for web testing, you can use the jeep-sqlite web component instead of Electron.
  • If you don’t register the plugin in the Electron bootstrap file (electron/src/index.ts), Capacitor won’t know about it → you’ll get the "not implemented" error.
  • Make sure you are using a recent version of both @capacitor-community/sqlite and @capacitor-community/electron (they must match your Capacitor version).

Aunt Gemini:


✦ This error, "CapacitorSQLite" plugin is not implemented on electron, means that the Capacitor SQLite plugin you're using doesn't have the
necessary code to work with the Electron platform. Capacitor plugins need specific implementations for each platform (iOS, Android, Web,
Electron), and it seems the one you're using is missing the Electron part.

Here are the conceptual steps to resolve this, keeping in mind you want to avoid new installations if possible:

Option 1: Use the Web/PWA Implementation (Recommended)

The @capacitor-community/sqlite plugin often has a web-based fallback that uses a library like sql.js to provide SQLite functionality directly
in the browser (or, in this case, the Electron renderer process). You may need to explicitly configure the plugin to use this web-based
implementation when running on Electron.

Instructions:

  1. Check for a Web-Based Fallback: Look into the documentation for your version of @capacitor-community/sqlite to see how to enable the PWA/Web
    platform support.
  2. Force Web Platform: In your Electron's main process file (often electron/src/index.ts or similar in a Capacitor project), you might need to add
    code that tells Capacitor it's running on the web. Look for where you initialize the Capacitor Electron app and see if you can force the web
    platform.
  3. Conditional Plugin Initialization: In your application's startup code, you may need to conditionally initialize the SQLite plugin based on the
    platform.

:information_source:Gemini CLI update available! 0.6.1 → 0.7.0
Installed with npm. Attempting to automatically update now...
1 import { Capacitor } from '@capacitor/core';
2 import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';
3
4 const platform = Capacitor.getPlatform();
5
6 if (platform === 'electron') {
7 // Potentially use a web-specific initialization if available
8 // This is a conceptual example; check your plugin's docs
9 const sqlite = new SQLiteConnection(CapacitorSQLite);
10 // ... continue with web-based setup
11 } else {
12 // Your existing mobile/other setup
13 }

Option 2: Use a Node.js SQLite Library via IPC

Since an Electron app has a full Node.js environment in its main process, you can use a standard Node.js SQLite library (like sqlite3 or
better-sqlite3) and communicate between your renderer process (the UI) and the main process (Node.js) using Electron's IPC (Inter-Process
Communication).

This is the most robust and common pattern for database access in Electron.

Conceptual Steps:

  1. Main Process (Node.js):

    • In your main Electron file (e.g., electron.js), import a Node.js SQLite library.
    • Set up IPC listeners (ipcMain.handle) to listen for requests from your UI (e.g., 'sqlite-query').
    • When a request comes in, execute the query against the database and return the result.
  2. Renderer Process (Your App Code):

    • Instead of calling the Capacitor plugin directly, create a "preload" script for your BrowserWindow to expose an IPC function.
    • In your app code, call this function, which will use ipcRenderer.invoke to send the query to the main process and get the result back.

This approach separates the database logic into the Node.js backend of your Electron app, which is a more standard architecture.

Since you prefer not to install new packages, you would first need to check your package.json to see if sqlite3 or a similar library is already
a dependency. If not, this approach would require an installation.

Given the error, your current plugin is not compatible out-of-the-box. The path of least resistance is to investigate Option 1 and see if you
can force the plugin to use its web-based implementation within your Electron environment.

Is a lot easier getting these two to explain it @franse!

:innocent:

1 Like

Thanks @Cheese, I'm testing importing it on index.js, like the old way

The problem and the question is, how to use the Wappler one: flow -> sqlite

AI doesn't seem to understand it very well :frowning:

I will check it out.

Should be working the capacitor community SQLite plugin though that we are using as well in Wappler.

found bug report bout this:

multiple solutions are offered so check which ones works and let me know so I can see if we can incorporate it in Wappler.

Sorry @Cheese - GipitEE and Gemini got it all wrong :slight_smile:

2 Likes

Seems I didn't do a good research about it, missed that :melting_face:

Changing package.json on /electron with:

  "dependencies": {
    "@capacitor-community/electron": "^5.0.0",
    "@capacitor-community/sqlite": "^7.0.0",
    "better-sqlite3-multiple-ciphers": "^11.9.1",
    "chokidar": "~3.5.3",
    "crypto": "^1.0.1",
    "crypto-js": "^4.2.0",
    "electron-is-dev": "~2.0.0",
    "electron-json-storage": "^4.6.0",
    "electron-serve": "~1.1.0",
    "electron-unhandled": "~4.0.1",
    "electron-updater": "^5.3.0",
    "electron-window-state": "^5.0.3",
    "jszip": "^3.10.1",
    "node-fetch": "^2.7.0",
    "reflect-metadata": "^0.2.2",
    "typeorm": "^0.3.21"
  },
  "devDependencies": {
    "@types/better-sqlite3": "^7.6.13",
    "@types/crypto-js": "^4.2.2",
    "@types/electron-json-storage": "^4.5.4",
    "electron": "^26.2.2",
    "electron-builder": "~23.6.0",
    "electron-rebuild": "^3.2.9",
    "typescript": "^5.0.4"
  },

And after npm build change: /electron/build/src/rt/electron-plugins.js
From:

const CapacitorCommunitySqlite = require('..\\..\\..\\node_modules\\@capacitor-community\\sqlite\\electron\\dist\\plugin.js');
module.exports = {
    CapacitorCommunitySqlite,
};

To

const CapacitorCommunitySqlite = require('../../../node_modules/@capacitor-community/sqlite/electron/dist/plugin.js');

module.exports = {
    CapacitorCommunitySqlite: CapacitorCommunitySqlite.default,
}

I have another beautiful problem but sqlite is working :slight_smile:
Thanks @George


  1. The package.json has to be changed, some sort of dependency issue is going on, will check one by one
  2. Wappler run using npm run build which overwrites /electron-plugin.js so has to be manually changed or modify that package.json script with a js fix that replaces the original (I'm sure that chatgipiti can do the job :smiley:)