NgModule'AppModule'的提供程序无效

时间:2019-02-18 15:18:10

标签: ionic-framework ionic3

当我有新的提供者时,我不明白为什么我会一遍又一遍地出现此错误。当我有任何其他提供商(例如地理位置等)时,出现此错误:

  

错误:未捕获的错误:NgModule'AppModule'的提供程序无效   -仅允许提供者和类型的实例,获得:[StatusBar,SplashScreen,?[object Object]?,...]

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 { ImagePicker } from '@ionic-native/image-picker';
import { Crop } from '@ionic-native/crop';
import { AuthService } from '../pages/core/auth.service';
import { UserService } from '../pages/core/user.service';
import { FollowService } from "../pages/core/follow.service";
import { AngularFireModule } from 'angularfire2';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { environment } from '../environment/environment';
import { MyApp } from './app.component';
import { LoginPage } from '../pages/login/login';
import { RegisterPage } from '../pages/register/register';
import { WelcomePage } from '../pages/welcome/welcome';
import { HomePage } from '../pages/home/home';

@NgModule({
declarations: [
MyApp,
LoginPage,
RegisterPage,
WelcomePage,
HomePage,
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(environment.firebase),
AngularFireAuthModule,
AngularFireDatabaseModule,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
LoginPage,
RegisterPage,
WelcomePage,
HomePage,
],
providers: [
StatusBar,
SplashScreen,
ImagePicker,
Crop,
AuthService,
UserService,
FollowService,  
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}

2 个答案:

答案 0 :(得分:3)

听起来像您正在将Ionic 4支持的节点模块与Ionic 3应用程序一起使用。 以 Geolocation 为例。

如果要在Ionic 3应用程序中安装@ionic-native/geolocation模块,则需要使用 @4 ,如下所示。

npm install @ionic-native/geolocation@4

您需要为所有Ionic3提供程序执行此操作。

答案 1 :(得分:1)

尝试在离子4中按如下所示将/ngx添加到路径:

import { File } from '@ionic-native/file/ngx';