Capacitor storage error: no provider for storage

I am trying to add capacitor storage to an app. I have installed capacitor storage per the instructions:

npm install @capacitor/storage
npx cap sync

I am trying to use the storage API from within a service:

import { Injectable } from ‘@angular/core’;

import { Storage } from ‘@capacitor/storage’;

@Injectable({
providedIn: ‘root’
})
export class StorageService {
readyPromise: Promise ;
isStorageReady: boolean = false ;
storageValuesTmp: string = “” ;
storageObj: {[k: string]: any} = {};

agentCode:    string  = "" ;


// ---------------------------------
constructor(public storage: Storage) {
}



}

However, Ionic Lab gives me the following error (in the console):

ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(SettingsPageModule)[StorageService → StorageService → StorageService → Storage → Storage → Storage]:
NullInjectorError: No provider for Storage!

My setup is as follows:

C:\mobile.…>ionic info

Ionic:

Ionic CLI : 6.17.1 (C:\Users\ALFON1\AppData\Roaming\nvm\v14.17.6\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.1.4
@angular-devkit/build-angular : 13.3.5
@angular-devkit/schematics : 13.3.4
@angular/cli : 13.3.5
@ionic/angular-toolkit : 6.1.0

Capacitor:

Capacitor CLI : 3.5.1
@capacitor/android : not installed
@capacitor/core : 3.5.1
@capacitor/ios : not installed

Utility:

cordova-res : 0.15.3
native-run : 1.5.0

System:

NodeJS : v14.17.6 (C:\Program Files\nodejs\node.exe)
npm : 6.14.15
OS : Windows 10

I am sure this is something trivial, but I have spent several hours trying to find it to no avail. Any help will be highly appreciated.

Hmmm…I am not familiar with Angular, but it appears that it is trying to inject Storage in the constructor. I would try removing it from the constructor. Storage is a constant so you just use it Storage.set or Storage.get, etc.

1 Like