Promise does not work in RC 2


#1

Hi Devs!

I built my app with ionic 2 beta in which i uses promises to return e.g. LocalStorage data or http response data. Now i upgraded to RC2 and suddenly the promise.es2015.lib is not found - can somebody please help me with this?

I also noticed that LocalStorage was removed? What is the best option to use in future?

Greetings Daniel


#2

The best idea for storage is currently the new Ionic Storage package. This package will try to use the best available database in this order:

Currently the ordering is SQLite, IndexedDB, WebSQL, and LocalStorage.

Regarding promise.es2015.lib, maybe this has to do with changes in the build system that were recently introduced. Try to start a fresh app using the current RC2 and see if you can import your lib.

Otherwise, why not simply use the HTTP requests with Angular 2 as they are? There’s no reason top change that behaviour (in general).


#3

Hi,
first of all, thanks for the reply.

I have another question to Ionic Storage - i have installed it on one of my ionic 2 beta apps - when i say “ionic build ios” i get the following error message:

/node_modules/@ionic/storage/es2015/index.js:1
import { Storage } from ‘./storage’;
^
ParseError: ‘import’ and ‘export’ may appear only with ‘sourceType: module’

Can you please help me on this - i really love the idea of IonicStorage.

Thanks!


#4

To import storage use the code below
import { Storage } from ‘@ionic/storage’;


#5

Try it on a fresh starter project. If that works, there’s something janky with your project’s configuration files. Generally speaking, when that happens, it’s often easier to parachute your code into a new project than it is to figure out what bits of what config files need to be tweaked.


#6

I am using the code you mentioned. The line "import { Storage } from ‘./storage’; is line 1 from index.js in the /node_modules/@ionic/storage/es2015/ folder

In my code im using: import { Storage } from ‘@ionic/storage’;


#7

Thank you - I will give it a try. :relieved: