35

I got this error after updating to angular 17:

NG02801: Angular detected that `HttpClient` is not configured to use `fetch` APIs. It's strongly recommended to enable `fetch` for applications that use Server-Side Rendering for better performance and compatibility. To enable `fetch`, add the `withFetch()` to the `provideHttpClient()` call at the root of the application.

I think after coding my services and importing HttpClient via inject functions it reached to this.

3 Answers 3

61

NG02801 is not an error but a warning that encourage the developers to enable the fetch implementation of the HttpClient.

To do this, just call provideHttpClient(withFetch()) in your app.config.ts file.

Sign up to request clarification or add additional context in comments.

10 Comments

does this mean we can remote HttpClientModule? and provide it with that instead?
Use HttpClientModule when you bootstrap an AppModule and provideHttpClient when you bootstrap an AppComponent !
Is there any document to reference this setup? Couldn’t find same behavior from http client module
What are you looking for exactly ? It should be used with the helpers mentionned here : angular.io/api/common/http/provideHttpClient
is HttpClientModule using fetch API as well?
|
17

use this

import { provideHttpClient, withFetch } from '@angular/common/http';

export const appConfig: ApplicationConfig = {
  providers: [provideHttpClient(withFetch()), provideRouter(routes), provideClientHydration()]
};

2 Comments

what if i dont have appConfig file?
@Omar I believe you can just remove the HttpClientModule import from your app.module.ts and put provideHttpClient(withFetch()) in the providers.
3

If the problem still exists, even if you have included in main.ts or other files.

import { provideHttpClient, withFetch } from "@angular/common/http";

providers : [provideHttpClient(withFetch())]

Keep your server running in a terminal and run your app in other terminal, if the server is present in the same app.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.