我使用下面的最新版本的Ionic CLI v4.9.0创建了新的Ionic 3应用程序
$ ionic start Ionic3Project blank --type ionic-angular
默认情况下会创建V4 Ionic项目。
然后,我按照本机应用程序版本插件here
的步骤进行操作在导入 app.module.ts 文件
时遇到控制台错误Uncaught Error: Invalid provider for the NgModule 'AppModule' - only instances of Provider and Type are allowed, got: [StatusBar, ?[object Object]?, ...]
at syntaxError (compiler.js:486)
at compiler.js:15784
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (compiler.js:15752)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15320)
at JitCompiler._loadModules (compiler.js:34413)
at JitCompiler._compileModuleAndComponents (compiler.js:34374)
at JitCompiler.compileModuleAsync (compiler.js:34268)
at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:239)
at PlatformRef.bootstrapModule (core.js:5578)
app.module.ts 文件
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 { AppVersion } from '@ionic-native/app-version';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
AppVersion, <-- Error [[ts]
Type 'AppVersionOriginal' is not assignable to type 'Provider'.
Type 'AppVersionOriginal' is missing the following properties from type 'FactoryProvider': provide, useFactory [2322]]
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
更新:最后,我找到了此问题的解决方案和解释here:P
答案 0 :(得分:4)
此问题是由于离子新更新(释放离子4)引起的 您必须像这样导入ionic 3的插件:
import { PluginName} from '@ionic-native/pluginName/ngx';
答案 1 :(得分:0)
由于ionic 4的新更新而引发此错误。 上面给出的解决方案将完美地工作。
但是,必须在整个项目中完成此操作,以避免出现此错误。 另一种方法是回滚到插件的先前版本。