Ionic 3.6.0 and PouchDB / SQLite

Hi.

Does anyone know of a working solution for Ionic@3.6?

cli packages: (/Users/mr/workspace/my-app/node_modules)

@ionic/cli-plugin-cordova       : 1.6.2
@ionic/cli-plugin-ionic-angular : 1.4.1
@ionic/cli-utils                : 1.7.0
ionic (Ionic CLI)               : 3.7.0

global packages:

Cordova CLI : 7.0.1

local packages:

@ionic/app-scripts : 2.1.3
Cordova Platforms  : android 6.2.3 ios 4.3.1
Ionic Framework    : ionic-angular 3.6.0

System:

Android SDK Tools : 26.0.2
Node              : v6.11.2
OS                : macOS Sierra
Xcode             : Xcode 8.3.3 Build version 8E3004b
ios-deploy        : 1.9.1
ios-sim           : 5.0.13
npm               : 5.3.0 

The version info from package.json:

“cordova-plugin-sqlite-2”: “^1.0.4”,
“pouchdb”: “6.3.4”,
“pouchdb-adapter-cordova-sqlite”: “2.0.2”,

I want to use sqlite for storing my data on the device so that I can pre-populate it, so have done what I’ve done before:

import PouchDB from ‘pouchdb’;
declare var require: any;

Then in my method …

PouchDB.plugin(require(‘pouchdb-adapter-cordova-sqlite’));
this.db = new PouchDB(‘mydb’, { adapter: ‘cordova-sqlite’ });

This just fails now, when it used to be fine:

TypeError: WebSqlPouchCore.call is not a function
at PouchDB$5.CordovaSQLitePouch (file:///android_asset/www/build/vendor.js:138430:19)
at new PouchDB$5 (file:///android_asset/www/build/vendor.js:127989:36)
at file:///android_asset/www/build/main.js:1634:36
at t.invoke (file:///android_asset/www/build/polyfills.js:3:9283)
at Object.onInvoke (file:///android_asset/www/build/vendor.js:4508:37)
at t.invoke (file:///android_asset/www/build/polyfills.js:3:9223)
at r.run (file:///android_asset/www/build/polyfills.js:3:4452)
at file:///android_asset/www/build/polyfills.js:3:14076
at t.invokeTask (file:///android_asset/www/build/polyfills.js:3:9967)
at Object.onInvokeTask (file:///android_asset/www/build/vendor.js:4499:37)

I’ve tried the suggested workarounds and fixes from this topic, but all to no avail. If anyone has any working solution or thoughts I’d be very grateful.

I couldn’t get this to work with Ionic 3.6.0 (not clever enough), but have got it working with 3.5.3 and the following:

“dependencies”:{

“cordova-plugin-sqlite-2”: “^1.0.4”,
“ionic-angular”: “3.5.3”,
“pouchdb”: “6.3.4”,
“pouchdb-adapter-cordova-sqlite”: “2.0.2”,

}
“devDependencies”: {
@ionic/app-scripts”: “2.0.1”,
@ionic/cli-plugin-cordova”: “1.4.0”,
@ionic/cli-plugin-ionic-angular”: “1.3.1”,
“typescript”: “2.3.4”
},

I also switched back to version 3.5.0 of the Ionic CLI…

So. I didn’t need any of the websql plugins or individual pouchdb modules as per this topic, but probably the dev dependencies from that topic were the clincher. However, I’ll freely admit I have no idea what fixed what, what broke what or why. I suspect that it’s to do with the latest Ionic app-scripts version somehow.

I hope that later versions of PouchDB and Ionic start playing together (I’m sure they will), but in the meantime I’m OK sticking with Ionic 3.5.3 for this current project.

Hi,
This doesn’t seem to be related to Ionic in the end.
The root cause has been identified & fixed in the pouchdb adapter sqlite repo : https://github.com/pouchdb-community/pouchdb-adapter-cordova-sqlite/issues/78

So you can fix the issue by patching the lib/index.js file in your node_modules/pouchdb-adapter-cordova-sqlite, until the fix is released.

HTH

1 Like

Thanks for letting me know. Appreciated.