Error: Encountered undefined provider!

Suddenly today it’s showing providers error into my application.
I have created a provider which contains common functions which are used throughout the app.
But when I created a new page and imported this provider into a new page then it’s showing undefined provider error.

I have checked it’s already imported into app.module.ts and it’s working into existing pages where it has been imported before.

Please help out with this. I am stuck at this point, my app doesn’t run.

1 Like

i also facing the same error.please help me in this case.

Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using ‘barrel’ index.ts files.

Can you show your code? Also, try to redo an ionic serve again.

When I had this problem like 2 weeks ago, it was caused by a circular dependency, but it could be something else to you, we have very little context since you don’t provide anything else.

Can you share a snippet? That would definitely help solving the issue

import { Component } from ‘@angular/core’;
import { NavController, NavParams,ViewController,ToastController,LoadingController } from ‘ionic-angular’;
import { CommonService } from “…/…/providers/common”;
import { GlobalVars } from “…/…/providers/global”;
import { Http } from “@angular/http”;
@Component({
selector: ‘page-responsetemplate’,
templateUrl: ‘responsetemplate.html’,
//providers: [CommonService, GlobalVars]

})
export class ResponsetemplatePage {
public template;
public language_common;
public loader;
public loadflag = false;
constructor(public navCtrl: NavController, public navParams: NavParams,public viewCtrl: ViewController,public ulrs: GlobalVars,private toastCtrl: ToastController,private loadingCtrl: LoadingController,public http: Http/,public cmn:CommonService/) {
this.language_common = JSON.parse(
window.localStorage.getItem(“lang_common”)
);
}

ionViewDidLoad() {
console.log(‘ionViewDidLoad ResponsetemplatePage’);
}
dismiss() {
this.viewCtrl.dismiss();
}
save(){
if(this.template == “” || this.template == undefined){
this.showToast(“Please enter review response you want to save.”);
return;
}

}

showToast(message: String) {
let toast = this.toastCtrl.create({
message: message.toString(),
duration: 3000
});
toast.present();
}

showLoader1(message: String) {
return new Promise((resolve, reject) => {
if (message != undefined) {
this.loader = this.loadingCtrl.create({
content: message.toString()
});
this.loader.present();
this.loadflag = true;
}
});
}
hideLoader() {

if (this.loadflag) {
  this.loader.dismiss();
  this.loadflag = false;

}

}
}

the functions after save are into my CommonService. I have to rewrite these code into my file as it showing me error into this.

@SanduCuragau Sorry I couldn’t share the context before as I have to take permission from my senior developer before it.

@vivek-23 my ionic serve is working fine, but when I run the URL into browser then it’s showing this error. Below is the ionic serve

ionic serve --address 192.168.20.21 --port 2222
[WARN] Detected @ionic/cli-plugin-cordova in your package.json.

   As of CLI 3.8, it is no longer needed. You can uninstall it:
   
   npm uninstall --save-dev --save-exact @ionic/cli-plugin-cordova

[WARN] Detected @ionic/cli-plugin-ionic-angular in your package.json.

   As of CLI 3.8, it is no longer needed. You can uninstall it:
   
   npm uninstall --save-dev --save-exact @ionic/cli-plugin-ionic-angular

[INFO] Starting app-scripts server: --address 192.168.20.21 --port 2222 --livereload-port 35729 - Ctrl+C to
cancel
[08:31:39] watch started …
[08:31:39] build dev started …
[08:31:39] Proxy added: service links
[08:31:39] Proxy added: service links
[08:31:39] Proxy added: service links
[08:31:39] clean started …
[08:31:39] clean finished in 35 ms
[08:31:39] copy started …
[08:31:39] deeplinks started …
[08:31:40] deeplinks finished in 478 ms
[08:31:40] transpile started …
[08:31:46] transpile finished in 6.08 s
[08:31:46] preprocess started …
[08:31:46] preprocess finished in less than 1 ms
[08:31:46] webpack started …
[08:31:46] copy finished in 7.14 s
[08:31:52] webpack finished in 5.74 s
[08:31:52] sass started …
[08:31:53] sass finished in 1.08 s
[08:31:53] postprocess started …
[08:31:53] postprocess finished in 13 ms
[08:31:53] lint started …
[08:31:53] build dev finished in 13.81 s
[08:31:53] watch ready in 14.24 s
[08:31:53] dev server running: http://192.168.20.21:2222/

[INFO] Development server running
Local: http://localhost:2222
External: http://192.168.20.21:2222

Error when url is run into browser.

07-08-34-48

It seems like no one is interested in helping to fix this error.
So I will change from ionic framework to other framework.

@hemali2305 Have found anything?

Does this help?

yes i found the solution. it was circular dependency in common page.so i was resolve this issue by change the calling path and it will work.:grinning::grinning: