Here's a somewhat useless error I'm getting in my Angular/TypeScript application. Until someone makes the error message better, what can we do about this? What are the most likely situations that cause this to happen? Here my app.module.js file and home.ts files there.
When I remove file and file opener plugin it's not getting an error. If I include that plugin in home.ts it shows the error. What are the most likely situations that cause this to happen?
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) {
}
I got an error like this:
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)
You need to use File not FileOriginal. In my project i declare File as a provider and it work . Do you install it correctly ?
When you use this command ionic cordova plugin add cordova-plugin-file
, did you have any dependencies warning ?
Maybe the version of the plugin is not compatible with the ionic 3.
EDIT
Command :
ionic cordova plugin add cordova-plugin-file
npm install @ionic-native/file@4.2.0