question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SampleService using HttpClient results in 'No provider for Injector!' error for HttpHandler

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:24 (3 by maintainers)

github_iconTop GitHub Comments

37reactions
ggradnigcommented, Nov 10, 2018

For those who are still facing the issue: add the following configuration to the consumer application angular.json at projects/*/architect/build/options :

"preserveSymlinks": true

This resolved the issue on Windows 10.

11reactions
sfmxcommented, Feb 6, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullInjectorError: No provider for HttpHandler! despite ...
You can directly inject the instance of HttpClient in the constructor of component without adding it in providers. if you are using ......
Read more >
SampleService using HttpClient results in 'No provider for Injector ...
SampleService using HttpClient results in 'No provider for Injector !' error for HttpHandler. ... Then ran 'npm link' from the dist directory.
Read more >
How to fix No provider for HttpClient error in Angular
To fix NullInjectorError: No provider for HttpClient! follow the below steps 1. Open `app.module.ts` file 2. Import HttpClientModule from ...
Read more >
NullInjectorError: No provider for HttpHandler! Code Example
NullInjectorError: No provider for HttpHandler! ... import { HttpClientModule } from '@angular/common/http'; @NgModule({ imports: [ BrowserModule, ...
Read more >
NullInjectorError: No provider for HttpClient - test component ...
Trying to unit-test a component with service A in the providers array. Service A imports Service B which in turn imports Service C....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found