Amir Abaris
Amir Abaris

Reputation: 299

Angular detected that `HttpClient` is not configured to use `fetch` APIs. (Angular 17 - SSR)

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.

Upvotes: 29

Views: 41354

Answers (3)

Matthieu Riegler
Matthieu Riegler

Reputation: 55534

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.

Upvotes: 51

Meghana
Meghana

Reputation: 21

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.

Upvotes: 2

surendra d
surendra d

Reputation: 181

use this

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

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

Upvotes: 17

Related Questions