diff --git a/packages/common/http/src/provider.ts b/packages/common/http/src/provider.ts index 15ac02f2dc68..e4b3922e8d5c 100644 --- a/packages/common/http/src/provider.ts +++ b/packages/common/http/src/provider.ts @@ -89,6 +89,13 @@ export function provideHttpClient(...features: HttpFeature[]): `Configuration error: found both withXsrfConfiguration() and withNoXsrfProtection() in the same call to provideHttpClient(), which is a contradiction.` : ''); } + + if (featureKinds.has(HttpFeatureKind.RequestsMadeViaParent) && featureKinds.has(HttpFeatureKind.Fetch)) { + throw new Error( + ngDevMode ? + `Configuration error: found both withRequestsMadeViaParent() and withFetch() in the same call to provideHttpClient(), which is a contradiction.` : + ''); + } } const providers: Provider[] = [ diff --git a/packages/common/http/test/provider_spec.ts b/packages/common/http/test/provider_spec.ts index f0c1fe14ba58..4d69768dc99f 100644 --- a/packages/common/http/test/provider_spec.ts +++ b/packages/common/http/test/provider_spec.ts @@ -449,6 +449,24 @@ describe('provideHttpClient', () => { expect(consoleWarnSpy.calls.count()).toBe(0); }); + it('should throw when fetch is used together with withRequestsMadeViaParent()', () => { + TestBed.resetTestingModule(); + + TestBed.configureTestingModule({ + providers: [ + provideHttpClient(), + provideHttpClientTesting(), + ] + }); + + expect(() => createEnvironmentInjector( + [provideHttpClient( + withFetch(), + withRequestsMadeViaParent(), + )], + TestBed.inject(EnvironmentInjector))).toThrow(); + }); + it('should warn during SSR if fetch is not configured', () => { resetFetchBackendWarningFlag();