capacitor-community / sqlite

⚡Capacitor plugin for native & electron SQLite databases.
MIT License
496 stars 118 forks source link

Electron error `TypeError: Cannot read properties of undefined (reading 'CapacitorSQLite')` #242

Closed tobiasmuecksch closed 2 years ago

tobiasmuecksch commented 2 years ago

Describe the bug When I try to run my electron app, this exception is thrown:

Bildschirmfoto 2022-03-25 um 11 39 02

To Reproduce Steps to reproduce the behavior:

  1. clone demo project: git@github.com:tobiasmuecksch/capacitor-sqlite-angular.git
  2. npm install && cd electron && npm install && cd ..
  3. npx cap sync
  4. npx cap sync @capacitor-community/electron
  5. cd electron && npm run electron:start
  6. See the exception

Expected behavior No exception should be thrown, and electron should start as usual.

Desktop (please complete the following information):

Additional context

Ionic:

   Ionic CLI                     : 6.19.0 (/Users/tmuecksch/.npm-packages/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 6.0.13
   @angular-devkit/build-angular : 13.2.6
   @angular-devkit/schematics    : 13.2.6
   @angular/cli                  : 13.2.6
   @ionic/angular-toolkit        : 6.1.0

Capacitor:

   Capacitor CLI      : 3.4.3
   @capacitor/android : 3.4.3
   @capacitor/core    : 3.4.3
   @capacitor/ios     : 3.4.3

Utility:

   cordova-res (update available: 0.15.4) : 0.15.3
   native-run                             : 1.5.0

System:

   NodeJS : v16.14.2 (/usr/local/bin/node)
   npm    : 8.5.0
   OS     : macOS Monterey
jepiqueau commented 2 years ago

@tobiasmuecksch

git clone https://github.com/tobiasmuecksch/capacitor-sqlite-angular
npm install
cd electron
npm install
npm run build
cd ..
npm run build
npx cap sync
npx cap sync @capacitor-community/electron

open the capacitor.config.ts file and add the location for the electron databases

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'io.ionic.starter',
  appName: 'sqlite-ionic',
  webDir: 'www',
  bundledWebRuntime: false,
  plugins: {
    CapacitorSQLite: {
      electronWindowsLocation: 'CapacitorDatabases',
      electronMacLocation: 'CapacitorDatabases',
      electronLinuxLocation: 'CapacitorDatabases'
    }
  }
};

export default config;

and then

npm run build
npx cap copy
npx cap copy @capacitor-community/electron
cd electron
npm run electron:start

and that will do

tobiasmuecksch commented 2 years ago

@jepiqueau Thank you very much for your quick response. In fact that helped!

I've been following the readme.md here. I'd highly recommend you to add the information about the mandatory configuration in capacitor.config.ts there.

P.S.: At the very top of the readme you said this

Databases location for Electron can be set in the config.config.ts as followed:

"CAN be set" means to me, that I don't have to, if I'm okay with the default config. If it's mandatory you should better phrase it like this:

Databases location for Electron MUST be set in the config.config.ts as followed:

jepiqueau commented 2 years ago

@tobiasmuecksch i will have a look, there may be a bug there, i just changed all this in that release.

tobiasmuecksch commented 2 years ago

@jepiqueau I just found out, that when I run npx cap sync @capacitor-community/electron the configuration in capacitor.config.ts is automatically removed. That's quite confusing.