Ionic Storage problem


#1

With this code I always get the error: All declarations of ‘storage’ must have identical modifiers’

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

import {IonicStorageModule} from '@ionic/storage'

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}
import { Storage } from '@ionic/storage';

export class MyApp {
  constructor(private storage: Storage) { }

  storage.set('item1', 'item');

  storage.get('item2').then((val) => {
    console.log('Your age is', val);
  });
}

note: I got the code from the ionic docs


#2

Do you have “Storage” anywhere else?
What is your ionic info?


#3

I do not have storage anywhere else


#4

Please create a new project with ionic start and do only the exact things the docs tell you. Does it work then or do you get the same error? If you still get the error, please upload the whole project to Github and post the link so we can check the exact code.


#5

Yes it works! Thank you