I have installed NativeStorage correctly (that is, install the wrapper, provide it in my app module, install the cordova plugin and wait until platform.ready()
to use it) but when I call await this.nativeStorage.keys()
(or another function) I always get an error like this one:
index.js:12 Uncaught (in promise) TypeError: Object(…) is not a function TypeError: Object(…) is not a function
at NativeStorage.keys (index.js:11)
at :1:70
at :2:3
or
nativeStorage.setItem(‘test’, 100);
index.js:9 Uncaught TypeError: Object(…) is not a function
at NativeStorage.setItem (index.js:9)
at :1:42
The referenced code is:
NativeStorage.prototype.keys = function () { return cordova(this, "keys", {}, arguments); };
It does not matter if I run it with the --livereload
flag or do not.
If I access the plugin directly (window.NativeStorage
) it works. Do I have to do something extra?
One thing that may have helped is to search the forums for your error message and go through all the threads talking about not forgetting the trailing /ngx
on imports and aligning all your @ionic-native/*
parts to the same major version.
The fix was mixed. I had to align the @ionic-native/
parts and REMOVE /ngx
.
It did knew about adding /ngx
because it is on the docs. Is the version alignment documente anywhere?
When you had to remove the /ngx, i guess you are using ionic v3?
Yes Ionic 3. I am migrating my App to Ionic 4 and I have found that the user settings saved in @ionic/Storage are deleted because the webview Implementation changed. So I am doing a middle update to migrate the values to NativeStorage before I send the Ionic 4 update.
Sidenode: I am not sure if NativeStorage is actively maintained becase the last code commit was like 2 years ago…
Yeah you need the /ngx only from Version 4.* not for earlier Versions. Have you used the Ionic Storage in combination with the plugin cordova-sqlite-storage
?
No it was just Ionic Storage with the default driver (I think IndexedDB). That is why I have to migrate it myself.
But maybe you can migrate to sqlite if the plugin is not maintained
I thought about that also. I have two things as cons:
- I am really bad and inexpert with SQL queries. (But maybe it is a good time to start?)
- The SQLite repo it self recommends the Native Storage plugin for little non-complex data (I think the bigger object I store is around 32Kb)
You don’t need SQL queries, the @ionic/storage manages all for you. If you have installed the plugin, they use this, read here
Oh! do you mean with @Ionic/Storage, the problem is my app has user preferences saved so (as I understand) if I change the driver to SQLite the current data will be lost. And that is what I am trying to avoid.
I get that it’s confusing that there are so many moving parts of “Ionic”, but in this case I don’t think the framework version is the relevant bit. IIRC, it was @ionic-native/core
5.0 that changed the import syntax in order to facilitate supporting frameworks other than Angular.