NullInjectorError: No provider for Storage!

Hi, I am using @ionic/storage but I am getting the error NullInjectorError: No provider for Storage!. However, the Storage is imported in app.module:

imports: [
    BrowserModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    }),
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot(),
    PerfilUsuarioBajaPageModule,
    PerfilUsuarioDatosPageModule
  ]

What can be causing this?

Thanks.

Hi,

If you component is contained in one of your submodules (for example in PerfilUsuarioDatosPageModule), you need to add the ionic storage module to the imports of your submodule.

This happened to me and it was bec I wasn’t importing the package where I used it. Idk fpr wjat reason but if you don’t explicitly import it, it’ll use some other Storage which idk what it is.

So just import it wherever you use it:

import { Storage } from '@ionic/storage'

2 Likes