Ionic-app-scripts: Encountered undefined provider! Usually this means you have a circular dependencies

Created on 9 Apr 2017  路  28Comments  路  Source: ionic-team/ionic-app-scripts

Short description of the problem:

I am migrating to ionic 3 and i get the above error. I followed the instructions in this link
https://github.com/driftyco/ionic/releases and now i get this error.

I ran npm run ionic:build --prod it gives the below error but npm run ionic:build works perfectly fine

Which @ionic/app-scripts version are you using?
1.3,0

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

[00:10:06]  ngc started ...
[00:10:08]  ionic-app-script task: "build"
[00:10:08]  Error: Encountered undefined provider! Usually this means you have a circular dependencies (might be caused

            by using 'barrel' index.ts files.
Error: Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'b
arrel' index.ts files.
    at syntaxError (/Users/pr/workspace/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:1513:3
4)
    at /Users/pr/workspace/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:14398:40
    at Array.forEach (native)
    at CompileMetadataResolver._getProvidersMetadata (/Users/pr/workspace/ui/node_modules/@angular/compi
ler/bundles/compiler.umd.js:14383:19)
    at CompileMetadataResolver.getNgModuleMetadata (/Users/pr/workspace/ui/node_modules/@angular/compile
r/bundles/compiler.umd.js:14039:50)
    at addNgModule (/Users/pr/workspace/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:22526:
58)
    at /Users/pr/workspace/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:22537:14
    at Array.forEach (native)
    at _createNgModules (/Users/pr/workspace/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:2
2536:26)
    at analyzeNgModules (/Users/pr/workspace/ui/node_modules/@angular/compiler/bundles/compiler.umd.js:2
2411:14)

Most helpful comment

I had the same issue, but on my case i removed "storage" from providers
@NgModule({
providers: [ storage, ... ]
})
in app.module.ts
since @ionic/storage 2.x.x
we import IonicStorageModule instead of storage

All 28 comments

Same here. ionic build android --prod --release fails to build with above mentioned error.

Note, however, that a debug build with ionic build android works as expected.

Package.json dependencies are the same as in a new project (which builds ok in prod).

Same here. Is there a way to get more detailed error message, for example in which file the compiler failed or which dependency it didn't find? It probably is related to some Angular service that is no longer out of the box included and have to be included manually in app.modules. But now the question is which one.

Same problem here after upgrading to Ionic 3 as suggested at https://github.com/driftyco/ionic/releases.

@ThorConzales where you able to find out the missing dependency

@awebdeveloper I haven't tried to find out just yet, my project is pretty huge, hoping that someone else will stumble upon the solution.

I had the same issue, but on my case i removed "storage" from providers
@NgModule({
providers: [ storage, ... ]
})
in app.module.ts
since @ionic/storage 2.x.x
we import IonicStorageModule instead of storage

Yes! This was also my case. Many thanks @RomeoDenis !!

So, this was an issue on our code after all. Probably, this thread can be closed.

agree, remove Storage from providers resolve this issue for me

Same, removed Storage from providers and it worked! Thanks guys

thanks @RomeoDenis .. funciona!!!

@RomeDenise
Right on points, thanks a lot!!

@RomeoDenis thanks, but it isn't work for me in ionic3.

@mah14 look for something similar

@RomeoDenis you are the MVP. Thank you!

@RomeoDenis I don't have storage included in my providers, still I am getting this issue. Can you Help?

I don't have storage included in my providers either, I'm still getting this error as well.

EDIT: I solved this by removing a provider I had in my tabs.ts file. Check if your tabs.ts file is correct.

@RomeoDenis thank you man!

I am getting this error. It is kinda hard to figure what provider is having circular dependency. The error is already telling me an undefined provider: Error: Encountered undefined provider!...

Still having this Issue after removing Storagemodule! does someone have an idea how to detect this circular dependency issue?

iam getting this issue only in component level service.

after I move my provider at the end of the import, the problem is solved, not sure why it is

yay! Removing Storage fixed my issue when using ionic cordova build --prod --release android

This occurred to me when I switched from the "mock" item provider in the super template to a "real" item provider working against HTTP. There were a number of issues, but in this case one was that the real item provider didn't have "defaultItem", but item-detail expected it. The error was non-intuitive, but when I completely stopped ionic serve and re-ran I got a more useful error that pointed to this. In my case I removed ||items.defaultItem from item-detail.ts and it worked.

in my case it was a rebuild problem
i changed rootPage in app.component file and my app and ran into this error
after stoping ionic and serving again the problem was gone
just to be sure i did the same thing again and exact same scenario happened

In my case, I had a method marked as private. The error went away once I made it public.

I am still getting this error. my provider is like :
providers: [
ReduxStore,
FileChooserOriginal,
FilePathOriginal,
ExtractFileDataService,
AscendingSortPipe,
SearchFilterPipe,
TestOrderPipe,
ZoneFilter,
CSVToJSONService,
XMLToJSONService,
fetchEventLogs,
FileOriginal,
FileOpenerOriginal,
FileTransferOriginal,
FileTransferObject,
TXTToJSONService,
GroupbyattProvider,
updateStatistics,
consistencyCheckService,
SpeechRecognitionOriginal,
AppGlobals,
AlertService,
DatePickerOriginal,
SerialOriginal,
AppPreferencesOriginal,
ApploggerService,
AnimationService,
MergePreviousDataService,
BrowseFromMobileService,
ParseSiteInfoService,
IconAlert,
NetworkOriginal,
NetworkCheck,
Storage,
GetFileCreationDateService,
GetDirectoryStructureService,
AppService,
GetPdfData,
UploadJSON,
VisualPlanning,
POSTPDFFile
]

I am still getting this error. my provider is like :
providers: [
ReduxStore,
FileChooserOriginal,
FilePathOriginal,
ExtractFileDataService,
AscendingSortPipe,
SearchFilterPipe,
TestOrderPipe,
ZoneFilter,
CSVToJSONService,
XMLToJSONService,
fetchEventLogs,
FileOriginal,
FileOpenerOriginal,
FileTransferOriginal,
FileTransferObject,
TXTToJSONService,
GroupbyattProvider,
updateStatistics,
consistencyCheckService,
SpeechRecognitionOriginal,
AppGlobals,
AlertService,
DatePickerOriginal,
SerialOriginal,
AppPreferencesOriginal,
ApploggerService,
AnimationService,
MergePreviousDataService,
BrowseFromMobileService,
ParseSiteInfoService,
IconAlert,
NetworkOriginal,
NetworkCheck,
Storage,
GetFileCreationDateService,
GetDirectoryStructureService,
AppService,
GetPdfData,
UploadJSON,
VisualPlanning,
POSTPDFFile
]

@amitgandole Remove your Storage entry and I supose it will work.

I had the same issue, but on my case i removed "storage" from providers
@NgModule({
providers: [ storage, ... ]
})
in app.module.ts
since @ionic/storage 2.x.x
we import IonicStorageModule instead of storage

Thanks!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danbucholtz picture danbucholtz  路  4Comments

hermitdemschoenenleben picture hermitdemschoenenleben  路  3Comments

dbarrecoquel picture dbarrecoquel  路  3Comments

danbucholtz picture danbucholtz  路  4Comments

bastibense picture bastibense  路  3Comments