SampleService using HttpClient results in 'No provider for Injector!' error for HttpHandler
See original GitHub issueI generated a new module using yo and modified the SampleService to include HttpClient (module source code here…). Then ran ‘npm link’ from the dist directory.
I then created a new angular app (client source code here…), linked to the generated module locally using the command ‘npm link sturgeon’ and added references to the SampleService implemented in the module from the client.
When I try to run the application using ‘ng serve’ I get the error ‘No provider for Injector!’ for HttpHandler. If I try to add HttpHandler and as indicated by the error message, and then the next error for NgZone, then I get ‘Can’t resolve all parameters for NgZone: (?).’ So it looks like I’m going down the wrong path?
Could somebody please point me in the right direction and/or provide an example using HttpClient in the SampleService called from a separate client project which uses the service provided by the module?
Error: StaticInjectorError(AppModule)[HttpHandler -> Injector]:
StaticInjectorError(Platform: core)[HttpHandler -> Injector]:
NullInjectorError: No provider for Injector!
at _NullInjector.get (webpack-internal:///../../../core/esm5/core.js:1209)
at resolveToken (webpack-internal:///../../../core/esm5/core.js:1507)
at tryResolveToken (webpack-internal:///../../../core/esm5/core.js:1449)
at StaticInjector.get (webpack-internal:///../../../core/esm5/core.js:1317)
at resolveToken (webpack-internal:///../../../core/esm5/core.js:1507)
at tryResolveToken (webpack-internal:///../../../core/esm5/core.js:1449)
at StaticInjector.get (webpack-internal:///../../../core/esm5/core.js:1317)
at resolveNgModuleDep (webpack-internal:///../../../core/esm5/core.js:11052)
at _createClass (webpack-internal:///../../../core/esm5/core.js:11091)
at _createProviderInstance$1 (webpack-internal:///../../../core/esm5/core.js:11063)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:24 (3 by maintainers)
Top GitHub Comments
For those who are still facing the issue: add the following configuration to the consumer application
angular.json
atprojects/*/architect/build/options
:"preserveSymlinks": true
This resolved the issue on Windows 10.
I made the changes you suggested but I was still getting the same error. First I tried syncing the minimum versions between the module and consumer application for @angular as the module was using 5.0.0 and my consumer application was using 5.2.0, this however did not resolve the issue. I then reverted to importing HttpModule from @angular/http and using Http instead of HttpClient. After this change I was able to run the client without errors so I reinstated HttpClient which also works if HttpModule is left as an import as well.
But when I attempted to actually use either Http or HttpClient rather than just the declaration in the constructor I was again seeing errors this time such as, ERROR TypeError: Cannot read property ‘getCookie’ of null.
In the end the issue I was facing was due to linking the module locally. It seems on windows 10 at least this gets in the way and causes the errors I was seeing. I resolved the problem by removing the links I created previously and copying the module directly into the node_modules folder in the client project.