Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find database when launched in Electron #421

Closed
saintsatplay2015 opened this issue May 26, 2023 · 81 comments
Closed

Cannot find database when launched in Electron #421

saintsatplay2015 opened this issue May 26, 2023 · 81 comments

Comments

@saintsatplay2015
Copy link

saintsatplay2015 commented May 26, 2023

Describe the bug
Following errors are present when launching Ionic/Angular application with "@capacitor-community/sqlite": "^5.0.0" and "@capacitor-community/electron": "^4.1.2":

Cannot find module '/Volumes/Projects/htdocs/electron-ionic/ionic-sqlite/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node'

Cannot find module '/Volumes/Projects/htdocs/electron-ionic/ionic-sqlite/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node'

Error: Uncaught (in promise): Error: The jeep-sqlite element is not present in the DOM! Please check the @capacitor-community/sqlite documentation for instructions regarding the web platform.
Error: The jeep-sqlite element is not present in the DOM! Please check the @capacitor-community/sqlite documentation for instructions regarding the web platform.

To Reproduce
Steps to reproduce the behavior:

Create the application in Ionic 7/Angular 16 using the following steps:

ionic start ionic-sqlite blank --type=angular
cd ./ionic-sqlite/
npm run build
npm install --save @capacitor-community/electron
npx cap add @capacitor-community/electron

// Change into Electron directory and install node packages
cd ..
npm install --save @journeyapps/sqlcipher
npm install --save jszip
npm install --save [email protected]
npm run build --prod
cd ..
npm install --save @capacitor-community/sqlite
npm install --save @capacitor/camera
npm install --save @ionic/pwa-elements

// Sanity check to ensure ALL modules are installed that should be
cd electron 
npm install
npm run build --prod

cd ..
npm run build --prod
npx cap sync @capacitor-community/electron
npx cap copy @capacitor-community/electron
npx cap open @capacitor-community/electron

Expected behavior
I believe (perhaps incorrectly?) that I have imported the correct modules and followed the correct steps to be able to use the sqlite plugin within an Ionic 7 application launched as an Electron desktop app via the @capacitor-community/electron plugin.

When I perform a build and publish the application to electron for testing on my system using the following commands:

npm run build --prod
npx cap sync @capacitor-community/electron
npx cap open @capacitor-community/electron

The project is built, with no errors in the Ionic CLI, and launched as an Electron application but multiple errors are reported in the developer console of the Electron browser environment - please see attached screenshots below.

Screenshots

The errors thrown up when the application is launched in an Electron environment:

electron-sqlite-errors

The electron build source files that are present:

electron-environment-source

The capacitor configuration file copied to Electron on capacitor sync:
Electron-capacitor-configuration

Desktop (please complete the following information):

  • OS: Mac OS Venture 13.3.1 (MacBook Pro M1 chip)
  • Browser Electron
  • Version @capacitor-community/electron": "^4.1.2",

Additional context
Package.json file:

  "name": "ionic-sqlite",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "ng lint"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^16.0.0",
    "@angular/common": "^16.0.0",
    "@angular/compiler": "^16.0.0",
    "@angular/core": "^16.0.0",
    "@angular/forms": "^16.0.0",
    "@angular/platform-browser": "^16.0.0",
    "@angular/platform-browser-dynamic": "^16.0.0",
    "@angular/router": "^16.0.0",
    "@capacitor-community/electron": "^4.1.2",
    "@capacitor-community/sqlite": "^5.0.0",
    "@capacitor/app": "5.0.2",
    "@capacitor/camera": "^5.0.2",
    "@capacitor/core": "5.0.4",
    "@capacitor/haptics": "5.0.2",
    "@capacitor/keyboard": "5.0.2",
    "@capacitor/status-bar": "5.0.2",
    "@ionic/angular": "^7.0.0",
    "@ionic/pwa-elements": "^3.1.1",
    "ionicons": "^7.0.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.13.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^16.0.0",
    "@angular-eslint/builder": "^16.0.0",
    "@angular-eslint/eslint-plugin": "^16.0.0",
    "@angular-eslint/eslint-plugin-template": "^16.0.0",
    "@angular-eslint/schematics": "^16.0.0",
    "@angular-eslint/template-parser": "^16.0.0",
    "@angular/cli": "^16.0.0",
    "@angular/compiler": "^16.0.0",
    "@angular/compiler-cli": "^16.0.0",
    "@angular/language-service": "^16.0.0",
    "@capacitor/cli": "5.0.4",
    "@ionic/angular-toolkit": "^9.0.0",
    "@types/jasmine": "~4.3.0",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "5.3.0",
    "@typescript-eslint/parser": "5.3.0",
    "eslint": "^7.26.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~4.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "ts-node": "^8.3.0",
    "typescript": "~5.0.2"
  },
  "description": "An Ionic project"
}

Does the Electron version need to mirror the Web set up for SQLite and use the jeep-sqlite plugin?

I could not see anything in the Electron documentation for the SQLite plugin that stated this was a requirement yet the error, when published to Electron, seems to suggest that this is the case??

I just need to clarify that I haven't missed any vital steps in getting this plugin to work with Electron, that the documentation isn't incomplete or that there isn't a bug here.

It's likely a bone-headed mistake on my part but I really appreciate any help that can be provided here :)

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 you just forgot to do after the run build to do
npx cap copy @capacitor-community/electron.

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 By the way i usually update the package.json of the electron folder to:

  "dependencies": {
    "@capacitor-community/electron": "^4.1.2",
    "@capacitor-community/sqlite": "^5.0.0",
    "@journeyapps/sqlcipher": "^5.3.1",
    "chokidar": "~3.5.3",
    "electron-is-dev": "~2.0.0",
    "electron-serve": "~1.1.0",
    "electron-unhandled": "~4.0.1",
    "electron-updater": "~5.0.1",
    "electron-window-state": "~5.0.3",
    "jszip": "^3.10.1",
    "node-fetch": "2.6.7"
  },
  "devDependencies": {
    "electron": "^22.0.0",
    "electron-builder": "24.0.0",
    "electron-rebuild": "^3.2.7",
    "typescript": "~4.3.5"
  },

So you delete the node_modules folder and the package-lock.json
and redo

npm install
npm build

@saintsatplay2015
Copy link
Author

@jepiqueau Thanks for your prompt reply, much appreciated.

I made the changes that you suggested in the electron folder - deleting the node_modules and package.lock.json files, updating the package.json file to the dependencies and devDependencies that you listed and saved those before running npm install and npm run build.

No problem there.

Changing back to the parent ionic project root directory and running the following commands:

npm run build --prod
npx cap copy @capacitor-community/electron
npx cap open @capacitor-community/electron

Unfortunately the same errors are still present.

The app is launched but the electron develop console consistently displays the following:

electron-sqlite-errors

Does the Electron version need the jeep-sqlite plugin?

I have not installed this, nor made any configurations relating to this, as I thought this applied purely to web only.

@saintsatplay2015
Copy link
Author

saintsatplay2015 commented May 26, 2023

I have noticed an issue with one of the node module dependency errors reported in the previous screen capture:

Cannot find module '/Volumes/Projects/htdocs/electron-ionic/ionic-sqlite/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node

When I check the electron directory for this path I get the following:

/Volumes/Projects/htdocs/electron-ionic/ionic-sqlite/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-x64/node_sqlite3.node

The installed binding directory is napi-v6-darwin-x64 NOT napi-v6-darwin-arm64.

Is this an issue related with MacOS Ventura/M1 chip MacBook architecture??

Screenshot 2023-05-26 at 18 05 08

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 electron does not need jeep-sqlite component (only web). I do not have a M1 chip so it is certainly due to this as i tested on a ionic7 app and it works

@saintsatplay2015
Copy link
Author

saintsatplay2015 commented May 26, 2023

@jepiqueau Thanks for the reply.

I have no doubts that the plugin works (I have used this many times in the previous 2 years and appreciate your contributions to the wider development community).

So the issue relates to the incorrect architecture being installed or detected for the sqlcipher package when it comes to being installed on an M1 MacBook pro?

Do you know of any workaround for this?

I suspect this may become an issue for other M1 MacBook users (possibly even M2 chips too).

@jepiqueau
Copy link
Collaborator

@saintsatplay2015
i just publish ionic7-angular-sqlite-starter using Ionic 7 Angular 16 and Capacitor 5. See if it is working
I was reluctant to put back the encryption for Electron due to the use of @journeyapps/sqlcipher which was causing some issues but i was pushed by the developer community to do so.
Are you using database encryption?

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 I just find this sqlcipher-issue#413

@saintsatplay2015
Copy link
Author

@jepiqueau Thanks for the updates. I'll check these out and keep you informed as to progress with (hopefully) resolving this situation.

To answer your previous question - I am not currently using database encryption and have no immediate plans to do so.

I also appreciate that you might be caught between a rock and a hard place with the developer community and its requests so many thanks for your time and assistance. It does NOT go unappreciated believe me.

@saintsatplay2015
Copy link
Author

@saintsatplay2015 I just find this sqlcipher-issue#413

Yes, I saw this yesterday. I also came across this which is probably not useful in the context of this plugin (but appears to relate to M1 chip related architecture issue): https://stackoverflow.com/questions/72553650/how-to-get-node-sqlite3-working-on-mac-m1

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 Was it working fine wit the release 4.6.3 on the M1 MacBook? Have you try running the 4.8.0 or 5.0.0 on a Intel based MacBook? is that working?

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 If it works on Intel based MacBook can you rename the issue and 4.6.3 is not running on M1 MacBook, can you rename the issue M1 MacBook - Cannot find ...

@saintsatplay2015
Copy link
Author

saintsatplay2015 commented Jun 15, 2023

@jepiqueau installed and ran the Ionic 7/Angular/SQLite starter app.

This runs fine on ionic serve in the browser.

Running the following command:

npm run electron:start

Results in the following error thrown up in the console:

For help, see: https://nodejs.org/en/docs/inspector
in setupCapacitorElectronPlugins
Error: Cannot find module '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node'
Require stack:
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/sqlite/electron/dist/plugin.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/rt/electron-plugins.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/electron/dist/core/index.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/index.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js
- 
    at Module._resolveFilename (node:internal/modules/cjs/loader:963:15)
    at n._resolveFilename (node:electron/js2c/browser_init:2:109751)
    at Module._load (node:internal/modules/cjs/loader:811:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at Module.require (node:internal/modules/cjs/loader:1035:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js:4:15)
    at Module._compile (node:internal/modules/cjs/loader:1141:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1196:10)
    at Module.load (node:internal/modules/cjs/loader:1011:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/sqlite/electron/dist/plugin.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/rt/electron-plugins.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/electron/dist/core/index.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/index.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js',
    undefined
  ]
}```

Once again this is running an Apple M1 MacBook Pro using Venture 13.4 OS.

@saintsatplay2015
Copy link
Author

saintsatplay2015 commented Jun 15, 2023

This appears to relate, once again, with the incorrect path of the directory that is being published within the SQL Cipher node module: m1-chip-issue

The installed binding directory is napi-v6-darwin-x64 NOT napi-v6-darwin-arm64 (which is the error being thrown in the console).

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 you should raise this issue in @journeyapps/sqlcipher

@saintsatplay2015
Copy link
Author

@jepiqueau Will do - as I am also experiencing almost the same issue with the incorrect directory not being published on the following system with the Ionic 7/Angular/SQLite starter app:

  • Mac OS
  • Monterey 12.4
  • Intel Quad-Core i7
  • MB Pro 2016

In this instance, when running the npm run electron:start command I get the following error:

intel-chip-mac-issue-1

However this time there is NO directory being generated in the location where the error occurs:

intel-chip-mac-issue-2

I'll raise this will @journeyapps/sqlcipher and see what can be done.

Will post updates here (as surely I can't be the only one experiencing this?)

@saintsatplay2015
Copy link
Author

Raised an issue regarding this bug here: journeyapps/node-sqlcipher#111

@saintsatplay2015
Copy link
Author

@jepiqueau Thanks for your help - I appreciate this is NOT directly your issue (software dependencies can be such a headache to navigate).

It doesn't seem like there's any recent development on the sqlcipher project (2 years ago was the last update) and response to user issues is patchy to say the least.

That doesn't fill me with a lot of confidence for finding resolution to this issue (hopefully I'm wrong on this point).

If there is no response from the maintainer(s) of the project what steps would you recommend going forwards to resolve this issue? I suspect that I can't be the only developer experiencing this with trying to create electron builds on Mac?

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 i agree so that why i remove it 2years ago. But i was under the pressure of some developers to put it back. See if someone will look at it. Would may be i should look at 2 version one encrypted and one not?

@saintsatplay2015
Copy link
Author

@jepiqueau I appreciate you're caught between a rock and a hard place with trying to satisfy various demands on your time (who would be a developer? :D)

I'll keep you updated as to any possible response/progress from the SQL Cipher maintainer(s).

In the meantime if you wouldn't mind acting on your suggestion - to look at one version encrypted and the other version unencrypted - maybe that will provide some insight?? It can't hurt right!

Thanks once again for your prompt replies/assistance - they are greatly appreciated.

@saintsatplay2015
Copy link
Author

saintsatplay2015 commented Jun 16, 2023

Tried downgrading the version of sqlcipher in the electron package.json file down to 5.2.0:

> npm run build && electron --inspect=5858 ./


> [email protected] build
> tsc && electron-rebuild

⠹ Building module: sqlcipher, Completed: 0  CC(target) Release/obj.target/nothing/../../node-addon-api/nothing.o
  LIBTOOL-STATIC Release/nothing.a
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
  ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlcipher-amalgamation-3033000/sqlite3.c
/bin/sh: python: command not found
make: *** [Release/obj/gen/sqlcipher-amalgamation-3033000/sqlite3.c] Error 127
Error: `make` failed with exit code: 2
    at ChildProcess.onExit (/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/node-gyp/lib/build.js:203:23)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)

✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher'

Error: node-gyp failed to rebuild '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher'
    at ChildProcess.<anonymous> (/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@electron/rebuild/lib/module-type/node-gyp/node-gyp.js:118:24)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)`



Different error this time round - but same result.

@saintsatplay2015
Copy link
Author

Similar error to that with the latest version of SQL Cipher when downgrading to 5.3.0:

> [email protected] electron:start
> npm run build && electron --inspect=5858 ./


> [email protected] build
> tsc && electron-rebuild

✔ Rebuild Complete
Debugger listening on ws://127.0.0.1:5858/2a7fd910-99b3-4c94-8014-417220299866
For help, see: https://nodejs.org/en/docs/inspector
in setupCapacitorElectronPlugins
Error: Cannot find module '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/binding/napi-v6-darwin-arm64/node_sqlite3.node'
Require stack:
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/sqlite/electron/dist/plugin.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/rt/electron-plugins.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/electron/dist/core/index.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/index.js
- /Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js
- 
    at Module._resolveFilename (node:internal/modules/cjs/loader:963:15)
    at n._resolveFilename (node:electron/js2c/browser_init:2:109751)
    at Module._load (node:internal/modules/cjs/loader:811:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at Module.require (node:internal/modules/cjs/loader:1035:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js:4:15)
    at Module._compile (node:internal/modules/cjs/loader:1141:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1196:10)
    at Module.load (node:internal/modules/cjs/loader:1011:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3-binding.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@journeyapps/sqlcipher/lib/sqlite3.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/sqlite/electron/dist/plugin.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/rt/electron-plugins.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/@capacitor-community/electron/dist/core/index.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/build/src/index.js',
    '/Volumes/Projects/htdocs/electron-ionic/angular-starter/ionic7-angular-sqlite-starter/electron/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js',
    undefined
  ]
}
` 

@tobiasmuecksch
Copy link
Contributor

tobiasmuecksch commented Jun 16, 2023

Hi, I'm experiencing the very same bug.

But i was under the pressure of some developers to put it back.
I don't understand, why would someone want you to add a broken tool? After my last upgrade of this plugin I was forced to install this cipher-crap. Since then, my app stopped working on windows and linux.

@jepiqueau
I highly recommend to remove this dependency asap, since it seems to be abandoned.

@tobiasmuecksch
Copy link
Contributor

I've also asked the developers to mark the project as abandoned journeyapps/node-sqlcipher#112

@tobiasmuecksch
Copy link
Contributor

If you don't want to remove it; maybe you can change the code, that the node-sqlcipher module is only imported, when encryption is actually used by the app. Then I would have to install this broken lib and my app would start woking on windows again.

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch this is what i am doing right now the developper will have the choice between sqlite3 without encryption and @journeyapps/sqlcipher with encryption i am not confident in using a code which is not maintained

@tobiasmuecksch
Copy link
Contributor

@jepiqueau Thank you so much! That's a great solution 😄

@jepiqueau
Copy link
Collaborator

@saintsatplay2015 @tobiasmuecksch the new release 5.0.3 is doing this.
This version allows to use @journeyapps/sqlcipher or sqlite3 depending on the value of the new parameter electronIsEncryption in the capacitor.config.ts

  • true use @journeyapps/sqlcipher
  • false use sqlite3

in the electron folder you must do

npm install --save @journeyapps/sqlcipher
npm install --save sqlite3
npm install --save jszip
npm install --save [email protected]
npm install --save-dev @types/sqlite3

Can you test it and revert to me
@saintsatplay2015 Please close the issue if it works

@saintsatplay2015
Copy link
Author

@jepiqueau I will get some time to test this over the next few days and let you know the outcome. Thanks for all your hard work and assistance with this issue - much appreciated!

@tobiasmuecksch
Copy link
Contributor

Updating electron-builder to the latest version seems to help. But now I'm facing a new problem. I can't sign the resulting exe anymore. I'll have to investigate that further... Will get back here soon.

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch i finally get some progress by defining a GH_TOKEN in github and modifying some files

  • electron-builder.config.json
{
 "appId": "com.jeep.app.ionic7.angular.sqlite",
 "directories": {
   "buildResources": "resources"
 },
 "files": [
   "assets/**/*",
   "build/**/*",
   "capacitor.config.*",
   "app/**/*",
   "node_modules"
 ],
 "publish": {
   "provider": "github",
   "owner": "jepiqueau",
   "repo": "ionic7-angular-sqlite-starter"
 },
 "nsis": {
   "allowElevation": true,
   "oneClick": false,
   "allowToChangeInstallationDirectory": true
 },
 "win": {
   "target": "nsis",
   "icon": "assets/appIcon.ico"
 },
 "mac": {
   "category": "public.app-category.utilities",
   "target": "dmg"
 },
 "linux": {
   "target": "AppImage",
   "category": "Utility"
 }
}

  • package.json file
{
  "name": "ionic7-angular-sqlite-starter",
  "version": "1.0.0",
  "description": "A Starter App for Ionic7-Angular SQLite Capacitor",
  "author": {
    "name": "Jean Pierre Quéau",
    "email": "[email protected]"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/jepiqueau/ionic7-angular-sqlite-starter.git"
  },
  "license": "MIT",
  "main": "build/src/index.js",
  "scripts": {
    "build": "tsc && electron-rebuild",
    "electron:start-live": "node ./live-runner.js",
    "electron:start": "npm run build && electron --inspect=5858 ./",
    "electron:pack": "npm run build && electron-builder build --dir -c ./electron-builder.config.json",
    "electron:make": "npm run build && electron-builder build -c ./electron-builder.config.json -p always"
  },
  "dependencies": {
    "@capacitor-community/electron": "^4.1.2",
    "@capacitor-community/sqlite": "^5.0.4",
    "better-sqlite3-multiple-ciphers": "^8.4.0",
    "chokidar": "~3.5.3",
    "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.0.1",
    "electron-window-state": "~5.0.3",
    "jszip": "^3.10.1",
    "node-fetch": "2.6.7"
  },
  "devDependencies": {
    "@types/better-sqlite3": "^7.6.4",
    "@types/electron-json-storage": "^4.5.0",
    "electron": "^25.2.0",
    "electron-builder": "^24.4.0",
    "electron-rebuild": "^3.2.9",
    "typescript": "~4.3.5"
  },
  "keywords": [
    "capacitor",
    "electron",
    "sqlite"
  ]
}

now the npm run electron:make seems to finish successfully:

 ...
  • publishing      publisher=Github (owner: jepiqueau, project: ionic7-angular-sqlite-starter, version: 1.0.0)
  • uploading       file=ionic7-angular-sqlite-starter-1.0.0.dmg.blockmap provider=github
  • uploading       file=ionic7-angular-sqlite-starter-1.0.0.dmg provider=github
  • creating GitHub release  reason=release doesn't exist tag=v1.0.0 version=1.0.0
    [==] 100% 0.0s | ionic7-angular-sqlite-starter-1.0.0.dmg to github
queaujeanpierre@MacBook-Pro-de-Queau-Jean-Pierre electron % 

and now in the dist folder i got a `ionic7-angular-sqlite-starter-1.0.0.dmg

now when i installed and launched the app on the Mac

i got an error:

Unhandled Promise Rejection
Error: Cannot parse releases feed: Error: Unable to find latest version on GitHub (https://github.com/jepiqueau/ionic7-angular-sqlite-starter/releases/latest), please ensure a production release exists: SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/node_modules/builder-util-runtime/out/httpExecutor.js:150:42)
    at IncomingMessage.emit (node:events:513:28)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
    at Object.newError (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/node_modules/builder-util-runtime/out/index.js:47:19)
    at GitHubProvider.getLatestTagName (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/out/providers/GitHubProvider.js:147:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async GitHubProvider.getLatestVersion (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/out/providers/GitHubProvider.js:74:23)
    at async MacUpdater.getUpdateInfoAndProvider (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/out/AppUpdater.js:305:19)
    at async MacUpdater.doCheckForUpdates (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/out/AppUpdater.js:319:24),
XML:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
  <id>tag:github.com,2008:https://github.com/jepiqueau/ionic7-angular-sqlite-starter/releases</id>
  <link type="text/html" rel="alternate" href="https://github.com/jepiqueau/ionic7-angular-sqlite-starter/releases"/>
  <link type="application/atom+xml" rel="self" href="https://github.com/jepiqueau/ionic7-angular-sqlite-starter/releases.atom"/>
  <title>Release notes from ionic7-angular-sqlite-starter</title>
  <updated>2023-05-27T06:53:35Z</updated>
  <entry>
    <id>tag:github.com,2008:Repository/646061695/v0.0.1</id>
    <updated>2023-05-27T06:53:35Z</updated>
    <link rel="alternate" type="text/html" href="https://github.com/jepiqueau/ionic7-angular-sqlite-starter/releases/tag/v0.0.1"/>
    <title>v0.0.1</title>
    <content type="html">&lt;p&gt;initial commit&lt;/p&gt;</content>
    <author>
      <name>jepiqueau</name>
    </author>
    <media:thumbnail height="30" width="30" url="https://avatars.githubusercontent.com/u/16580653?s=60&amp;v=4"/>
  </entry>
</feed>
    at Object.newError (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/node_modules/builder-util-runtime/out/index.js:47:19)
    at GitHubProvider.getLatestVersion (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/out/providers/GitHubProvider.js:85:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async MacUpdater.getUpdateInfoAndProvider (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/out/AppUpdater.js:305:19)
    at async MacUpdater.doCheckForUpdates (/Applications/ionic7-angular-sqlite-starter.app/Contents/Resources/app.asar/node_modules/electron-updater/out/AppUpdater.js:319:24)

and if i press on OK the application start normally

if i go to the adress https://github.com/jepiqueau/ionic7-angular-sqlite-starter/releases i saw a release 1.0.0 Draft with 3 assets

So i do not know the reason why i got this error May be draft is not production

@tobiasmuecksch
Copy link
Contributor

tobiasmuecksch commented Jun 30, 2023

Try to remove the "publish": {} part in your electron-builder.config.json. I think this might be related to the electron-updater, which you don't need for your testing purpose.

@tobiasmuecksch
Copy link
Contributor

tobiasmuecksch commented Jun 30, 2023

Oh no, I just found out that publish: "never" is the correct value.

Source: electron-userland/electron-builder#1805

@tobiasmuecksch
Copy link
Contributor

tobiasmuecksch commented Jun 30, 2023

✅ macOS

Building and signing a macOS application works for me (including signing and notarization).

❌ windows

But I'm still struggling with windows. I can build the .exe but the signing process fails with this error:

Failed

Unrecognized file type: /Users/tmuecksch/Sites/my-app/electron/dist/win-unpacked/resources/app.asar.unpacked/node_modules/better-sqlite3-multiple-ciphers/build/Release/better_sqlite3.node

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch i remove electron-rebuild and change "publish": [], it builds well but i still get the same error when launching is it because i do not have an Apple developer account?
When you said it successful on Mac it is with the M1 chip? if it is all this work is not done for nothing.

@tobiasmuecksch
Copy link
Contributor

Yes, I'm working with a M1 MacBook Pro.

it builds well but i still get the same error when launching is it because i do not have an Apple developer account?

No, as the error states, it tries to read a json file from your repository.

Unable to find latest version on GitHub (https://github.com/jepiqueau/ionic7-angular-sqlite-starter/releases/latest), please ensure a production release exists: SyntaxError: Unexpected end of JSON input

Have you rebuilt and reinstalled the app, after changing the publish value to "never" ?

@tobiasmuecksch
Copy link
Contributor

Googling around didn't help me to find a solution. I've created an issue now here: m4heshd/better-sqlite3-multiple-ciphers#51

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch yes i did rebuild an reinstall the app

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch Can you show me how did you set the publish:"never" on which file ?

@tobiasmuecksch
Copy link
Contributor

Well, in fact my publish config looks like this, because I'm using electron-updater to auto-update my app.

electron-builder.config.json

  "publish": [
    {
      "provider": "generic",
      "url": "https://updates.my-app.com/"
    }
  ]

But since you're not using the auto-update my guess was, that you should disable this.

@tobiasmuecksch
Copy link
Contributor

My problem is I'm running out of time, since I'm departing for a 1-week vacation tonight. Otherwise, I'd take a look at your app and help you to fix it.
If the problem still persists, I will help you after my vacation.

FYI: I got an answer on my build problem. It seems, that better-sqlite3-multiple-cipher does not support cross compilation... That will be a problem for my build process. But I will think about that, after my vacation.

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch OK thanks for your help and have a good vacation time. I will keep you aware.

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch Any news?

@tobiasmuecksch
Copy link
Contributor

Not yet. I'm struggling to build a windows package and haven't had the time yet to investigate it further. I will do so, as soon as possible.

@tobiasmuecksch
Copy link
Contributor

tobiasmuecksch commented Jul 19, 2023

@jepiqueau Well, at least I've been able to build the latest @capacitor-community/sqlite on version 5.0.5. The bug I mentioned above in this thread was fixed in electron-builder two weeks ago.

See fix issue

Right now I'm still struggling with a setup to build the ^5.0.4-betabetter.0 version for windows. As it was stated in this issue they do not provide pre-built packages for windows. Therefore I need to build the app with a windows machine, which I'm still trying to get to work in a parallels machine on my Mac.

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch thanks for the news keep me aware on progress

@tobiasmuecksch
Copy link
Contributor

tobiasmuecksch commented Jul 22, 2023

@jepiqueau Allright; I give up. Working in a parallels win11 machine has its problems. I cannot find out why, but when I run npm run build in the electron folder, the command finishes without an error, but it does not create any files.

Then I said; okay - maybe it will work on a real win 10 machine. So I set up a win 10 machine with nodejs and what else you need to build the project. npm run build does work now, but I'm still experiencing serious issues when the builder tries to create a binary of better-sqlite3-multiple-ciphers. I've invested multiple hours just to figure out error message after error message, and I don't see the end of the tunnel.

Anyways - losing cross platform build capability would also be a big minus point for better-sqlite3-multiple-ciphers. It's sad, because better-sqlite3 is waaaay better than sqlite3 and you've invested a fair amount of work into the integration of it, but as of now, I don't see that it makes sense to continue working on this.

Since @capacitor-community/[email protected] can be built again with the latest version of electron-builder, I'd suggest, to keep the better-sqlite3 branch for the future and stick with sqlite3 for as long as possible.

@tobiasmuecksch
Copy link
Contributor

tobiasmuecksch commented Jul 23, 2023

Aww man. I've only tested windows deployment until now. I've now discovered, that I cannot build macOs anymore.... (@capacitor-community/sqlite on version 5.0.5)

As I found out, during the last update of electron-builder the reintroduced the error...
electron-userland/electron-builder#7652 (comment)

@tobiasmuecksch
Copy link
Contributor

A little update; there is still some discussion going on here: electron-userland/electron-builder#7652 maybe we don't have to give up on better-sqlite3 😃 I'll let you know, in case I get the build working.

@tobiasmuecksch
Copy link
Contributor

@jepiqueau Finally - success 🎉 I've been able to build and test@capacitor-community/sqlite@better. During my first tests it works perfectly fine and my app even feels like it's a bit faster than before 😃

I've even regained cross-building capabilities. I had to remove the --arm64 flag for the build process.

See: electron-userland/electron-builder#7652 (comment)

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch i am happy of this as i did not know what i can do to help you. Better-sqlite3 claimed that it is far faster than sqlite3. It would be nice if you could write a doc on what you did so others can benefit from your hard work giving the electron package.json ... if you do it make a PR and i will merge it thanks for your work and contribution

@tobiasmuecksch
Copy link
Contributor

Sure. It'll take a few days, until I have time for that, but I will do that.

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch When the doc is done i think we can close this issue
@saintsatplay2015 You did not comment so i am assuming that your problem is fixed

@tobiasmuecksch
Copy link
Contributor

@jepiqueau Well; I've investigated what in fact needs to be done to be able to build with the new better-sqlite3 package. Despite installing the dependencies you mentioned above it is only necessary to upgrade electron-builder to at least 24.6.3.

By the way; is it possible to integrate the dependencies like node-fetch etc. into the package, so the developers don't need to install it themselves?

I'm now deploying this to the beta channel of my app in order to test if there are any issues which I didn't notice.
I'll wait a few days for some feedback and let you know, whether my users found any issues.

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch OK il will mentioned it in the doc. No it is not possible the depencies which are required only for electron otherwise it will penalize the native part of the plugin where it is not needed

@tobiasmuecksch
Copy link
Contributor

All Right. I didn't know that.
Give me some time to make sure that the new bettersqlite3 version really works well.

@jepiqueau
Copy link
Collaborator

@tobiasmuecksch hope everything works well now with bettersqlite3. i will close the issue feel free to re-open it if require. Thanks for your contribution and support

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants