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?
Uncaught Error: Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.
at Object.syntaxError
at eval at Array.forEach (native) [<root>]
at CompileMetadataResolver._getProvidersMetadata
at CompileMetadataResolver.getNgModuleMetadata
at CompileMetadataResolver.getNgModuleSummary
at eval
...
in my case I just deleted the @Injectable() decorator from my service(cause it didn't need any services to be injected in it)
in my case, very simple, it was really undefined provider in the module definition.
Because the lib I used, had an option to dynamically change their providers and it was wrong configured, so it loaded
undefined
as providers.Got this error running --prod.
You can't import things like that:
You should use the full path
Sometime this issue occurred because of some dependency in third party api used in angular app. I faced same issue and resolved it using following steps:
I got my way around this by flattening all of the barrel imports(which kinda defeats the purpose of using barrel files in the first place, but I can't afford losing more time on this).
One possibility is trying to declare a service and module in the same file, and declaring the module before the service:
You can fix this by declaring the service first, or you can use
forwardRef
like this: