typeof XService is not assignable to type 'FactoryProvider'. Property 'provide' is missing
Asked Answered
U

4

11

I have an Angular 2 NgModule in a Ionic 2 mobile app defined like so:

@NgModule({
  declarations: [
    MyApp,
    HomePage,
  ],
  imports: [
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
  ],
  providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}, VatRatesDbService]
})
export class AppModule {}

and the service defined this way:

import { Injectable } from '@angular/core';
import * as PouchDB from 'pouchdb';

@Injectable()
export class VatRatesDbService {

  private _db;

  private constructor() {
    this._db = new PouchDB('rates.db', { adapter: 'websql' });
  }
}

However, I'm getting the following error at runtime:

Type 'typeof VatRatesDbService' is not assignable to type 'FactoryProvider'. Property 'provide' is missing in type 'typeof VatRatesDbService'.

Unskilled answered 9/2, 2017 at 21:43 Comment(0)
U
13

The solution is to remove the private modifier from the constructor. You simply cannot have an injectable service with a private constuctor.

public constructor() {
  this._db = new PouchDB('rates.db', { adapter: 'websql' });
}

or:

constructor() {
  this._db = new PouchDB('rates.db', { adapter: 'websql' });
}
Unskilled answered 9/2, 2017 at 21:43 Comment(0)
A
41

It happens because of ionic latest update for ionic 4.

You have to import it like this (adding '/ngx' )

import { PluginName} from '@ionic-native/pluginName/ngx';

Or, you can downgrade the plugin's version

It was happening to me with another plugin.

More info here

Arabeila answered 30/1, 2019 at 3:23 Comment(2)
This exactly fixed my issue. Thanks a lot!Dubbin
So simple ty! :)Cottontail
U
13

The solution is to remove the private modifier from the constructor. You simply cannot have an injectable service with a private constuctor.

public constructor() {
  this._db = new PouchDB('rates.db', { adapter: 'websql' });
}

or:

constructor() {
  this._db = new PouchDB('rates.db', { adapter: 'websql' });
}
Unskilled answered 9/2, 2017 at 21:43 Comment(0)
C
2

It work for me In Ionic 4

You have to import it like this (adding '/ngx' )

import { PluginName} from '@ionic-native/pluginName/ngx';

Cunha answered 23/1, 2021 at 16:53 Comment(0)
C
0

Source Link

I am facing this issue in latest Ionic 4 CLI version 4.9.0

When I created older version Ionic 3 application in latest CLI and installed Native plugin App Version I faced this error

[ts] Type 'AppVersionOriginal' is not assignable to type 'Provider'. Type 'AppVersionOriginal' is missing the following properties from type 'FactoryProvider': provide, useFactory [2322]

for that, we need to install an older version of the native plugin

Cavill answered 29/1, 2019 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.