Cannot resolve all parameters for 'Storage'(?, ?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Storage' is decorated with Injectable

`import {Storage,SqlStorage} from 'ionic-angular';
import {Injectable} from 'angular2/core';
import {Contact} from '../modules/Contact';

@Injectable()
export class DataService{
  private data:Array<Contact>;
  private storage:Storage;
  constructor(){
    this.storage=new Storage(SqlStorage,{name:'contact-app'});
    this.data=null;
    this.storage.get('contact-app').then((contacts)=>{
      this.data=JSON.parse(contacts);
    })
  }
  getData(){
    return this.storage.get('contact-app');
  }
  save(item){
    if(!this.data){
      this.data=[item];
      let newData=JSON.stringify(item);
      this.storage.set('contact-app',newData);
    }else{
      this.data.push(item);
      let newData=JSON.stringify(this.data);
      this.storage.set('contact-app',newData);
    }
  }

}`

error
app.bundle.js:17029Uncaught TypeError: Cannot read property ā€˜getOptionalā€™ of undefined
exports.PlatformRef_ = PlatformRef_;
function _runAppInitializers(injector) {
var inits = injector.getOptional(application_tokens_1.APP_INITIALIZER);

bug?

Iā€™ve the same issue. Did you solve it already?

This is my code:

import ā€˜es6-shimā€™;
import {App, Platform, Storage, SqlStorage} from ā€˜ionic-angularā€™;
import {StatusBar} from ā€˜ionic-nativeā€™;
import {TabsPage} from ā€˜./pages/tabs/tabsā€™;

@App({
providers: [Storage],
template: ā€˜<ion-nav [root]=ā€œrootPageā€>ā€™,
config: {
tabbarPlacement: ā€˜topā€™
}
// http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
static get parameters() {
return [[Platform]];
}

constructor(platform) {
this.rootPage = TabsPage;

platform.ready().then(() => {
  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  StatusBar.styleDefault();
  
  this.storage = new Storage(SqlStorage, null);
  this.storage.query("CREATE TABLE IF NOT EXIST people (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)").then((data) => {
      console.log("TABLE CREATED -> " + JSON.stringify(data.res));
  }, (error) => {
      console.log("ERROR -> " + JSON.stringify(error.err));
  })      
  
});

}
}

I have the same problem here did any body found a solution

I just downgraded storage to 1.1.6 in package.json manually

ā€œ@ionic/storageā€: ā€œ1.1.6ā€,

and then ran npm install. That fixed it for me

1 Like

@nishantpant it works for me.
something got wrong with ā€œ^1.1.6ā€

This has seemingly been fixed: https://github.com/driftyco/ionic-storage/blob/master/README.md#configuring-storage-new-in-117

1 Like

I donā€™t think Iā€™d say itā€™s been ā€œfixedā€ as much as it is that one must now use the bootstrap method in the stanza you linked, and not the one further up the page under ā€œUsageā€.

@nishantpant : Thank you. It worked. I changed from ā€œ@ionic/storageā€: ā€œ2.0.0ā€, to ā€œ@ionic/storageā€: ā€œ1.1.6ā€, and ran npm install.

To others stumbling across this thread: there are ways to make ionic-storage 2.0.0 work. You are probably still declaring Storage in a provider array somewhere. Take them all out. Donā€™t downgrade to 1.1.6.

@rapropos : Iā€™m also facing same issue. I know downgrade is not a right solution. As per your logic if I remove Storage from Provides array then while building it is asking for Storage provide missing. Can you please explain exactly what changes need to be done, so that it will be helpful for others too.

Hi all I have fixed issue by referring this link. Please refer link in which import @ionic/storage as IonicStorageModule and remove Storage from Providers array then it will start working. Downgrading is not a right option. This fix is for version 2.0.0.

2 Likes

The solution outlined here fixes this problem:

Update Steps:

  • Run npm install @ionic/storage@2.0.0 --save --save-exact
  • Remove Storage from your providers in app.module.ts
  • import { IonicStorageModule } from ā€˜@ionic/storageā€™ instead of import { IonicStorage } from ā€˜@ionic/storageā€™ in app.module.ts
  • Add IonicStorageModule.forRoot() to the imports array in app.module.ts
2 Likes

Yup. If youā€™re upgrading to Ionic 2.2.0 and above, Iā€™d suggest reading the update guide:

https://learnionic2.com/2017/03/12/whats-new-ionic-2-2-0-update/