# Capacitor - Native Storage fails

**URL:** <https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932>\
**Category:** Capacitor\
**Created:** [June 28, 2020, 10:01pm UTC](https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932 "2020-06-28T22:01:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elduderino15](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/elduderino15/32/105188_2.png) [@elduderino15](https://forum.ionicframework.com/u/elduderino15)\
**Post date:** [June 28, 2020, 10:01pm UTC](https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932/1 "2020-06-28T22:01:26Z")

</div>

I installed Native Storage

```auto
npm install cordova-plugin-nativestorage
npm install @ionic-native/native-storage
ionic cap sync

```

but now when I run

```auto
this.storage.getItem('user').then((d) => {console.log(d); return d;});

```

in the browser it fails with

```auto
ERROR Error: Uncaught (in promise): cordova_not_available

```

?

In my ionic3 version of the app that I am porting to 5 I was able to run native storage / a storage in the browser.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [June 29, 2020, 1:45am UTC](https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932/2 "2020-06-29T01:45:58Z")

</div>

NativeStorage != Ionic Storage.

NativeStorage stores stuff using OS-dependent lower-level primitives. Ionic Storage is much more portable, and is likely what you want if you need to fail over to localforage in a browser environment.

---

<div class="post-metadata">

**Author:** ![elduderino15](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/elduderino15/32/105188_2.png) [@elduderino15](https://forum.ionicframework.com/u/elduderino15)\
**Post date:** [June 29, 2020, 5:06am UTC](https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932/3 "2020-06-29T05:06:55Z")

</div>

Thanks, but why is local storage not listed in the native api documentation?

> **[Native APIs - Ionic Documentation](https://ionicframework.com/docs/native)**
>
> Ionic is the app platform for web developers. Build amazing mobile, web, and desktop apps all with one shared code base and open web standards

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [June 29, 2020, 5:32pm UTC](https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932/4 "2020-06-29T17:32:06Z")

</div>

I get that it’s confusing to have many things with similar names, but:

- [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) is a DOM thing. As poker players say, it’s dominated. In any situation, there’s _some_ better choice than this.
- [`localForage`](https://github.com/localForage/localForage) was originally developed by Mozilla to address the biggest shortcoming of `localStorage`: it’s not very reliably persistent and gets wiped out from under you at unpredictable times. So it has a similar API as `localStorage` but uses different and more persistent storage methods under the hood. It’s a decent choice for many situations, but…
- [Ionic Storage](https://github.com/ionic-team/ionic-storage) is a better choice for Ionic apps because it not only wraps `localForage` but also adds seamless support for SQLite if desired. It should be your primary go-to for storing persistent stuff in an Ionic app, especially if you need to support desktop browser environments without additional work on your part.
- [Native Storage](https://github.com/TheCocoaProject/cordova-plugin-nativestorage) we’ve talked about. If you need to share stored data amongst many different apps on iOS, this is the best way I know of to do it. Its downside is that it needs Cordova (may work with Capacitor, I haven’t tried).

---

<div class="post-metadata">

**Author:** ![elduderino15](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/elduderino15/32/105188_2.png) [@elduderino15](https://forum.ionicframework.com/u/elduderino15)\
**Post date:** [July 1, 2020, 9:29pm UTC](https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932/5 "2020-07-01T21:29:09Z")

</div>

Yeah, thanks @rapropos . In my ionic3 app I in fact used ionic storage. But, now that only Native Storage is listed on the seems Ionic5 default API documentation I thought had to use that one, ionic storage seems not listed so I thought it was not supported anymore.

I’m sorry about the confusion, but it’s not really clear from the current documentation how to properly install ionic storage with capacitor (to me, maybe I just do not see the link in the docs). On the GitHub page you shared it’s using the cordova installation commands.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [July 1, 2020, 9:33pm UTC](https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932/6 "2020-07-01T21:33:14Z")

</div>

> [@elduderino15](#):
>
> On the GitHub page you shared it’s using the cordova installation commands.

Only for the (totally optional) step of using the SQLite driver. If you are happy with the localforage driver - and I don’t know of any compelling reason _not_ to be - breeze right through ignoring that step. Just `npm i @ionic/storage` and do the stuff in the Usage section.

---

<div class="post-metadata">

**Author:** ![elduderino15](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/elduderino15/32/105188_2.png) [@elduderino15](https://forum.ionicframework.com/u/elduderino15)\
**Post date:** [July 1, 2020, 9:34pm UTC](https://forum.ionicframework.com/t/capacitor-native-storage-fails/191932/7 "2020-07-01T21:34:16Z")

</div>

Ok, thanks for the help. I’ll do that. Yeah, I just need to store JSONs, so local forage would be enough.
