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/