这是我在Angular / TypeScript应用程序中遇到的一个无用的错误。在有人更好地提出错误消息之前,我们可以做些什么呢?导致这种情况发生的最可能的情况是什么?这里是我的app.module.js文件和home.ts文件。
当我删除文件和文件开启插件时,它没有收到错误。如果我在home.ts中包含该插件,则会显示错误。导致这种情况发生的最可能的情况是什么?
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 { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { FileOriginal } from '@ionic-native/file';
import { FileOpenerOriginal } from '@ionic-native/file-opener';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
FileOriginal,
FileOpenerOriginal
]
})
export class AppModule {}
home.ts
import { FileOriginal } from '@ionic-native/file';
import { FileOpenerOriginal } from '@ionic-native/file-opener'
constructor(public navCtrl: NavController,private plt: Platform, private file: FileOriginal, private fileOpener: FileOpenerOriginal) {
}
我收到这样的错误:
Uncaught Error: Encountered undefined provider!
Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.)
at syntaxError (compiler.js:486)
at compiler.js:15767
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)
您需要使用File not FileOriginal。在我的项目中,我将File声明为提供者并且它可以工作。你正确安装吗?
当您使用此命令ionic cordova plugin add cordova-plugin-file
时,您是否有任何依赖性警告?
也许该插件的版本与离子3不兼容。
编辑
命令:
ionic cordova plugin add cordova-plugin-file
npm install @ionic-native/[email protected]