{"record":{"id":"9e20d8ffb6d39aed","repo":"angular/angular","slug":"withrequestsmadeviaparent-can-only-be-used-when","errorCode":null,"errorMessage":"withRequestsMadeViaParent() can only be used when the parent injector also configures HttpClient","messagePattern":"withRequestsMadeViaParent\\(\\) can only be used when the parent injector also configures HttpClient","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/common/http/src/provider.ts","lineNumber":290,"sourceCode":" * `withRequestsMadeViaParent` to be used at multiple levels, which will cause the request to\n * \"bubble up\" until either reaching the root level or an `HttpClient` which was not configured with\n * this option.\n *\n * This feature cannot be combined with `withFetch` or `withXhr` in the same\n * `provideHttpClient()` call.\n *\n * @see [HTTP client setup](guide/http/setup#withrequestsmadeviaparent)\n * @see {@link provideHttpClient}\n * @publicApi 19.0\n */\nexport function withRequestsMadeViaParent(): HttpFeature<HttpFeatureKind.RequestsMadeViaParent> {\n  return makeHttpFeature(HttpFeatureKind.RequestsMadeViaParent, [\n    {\n      provide: HttpBackend,\n      useFactory: () => {\n        const handlerFromParent = inject(HttpHandler, {skipSelf: true, optional: true});\n        if (ngDevMode && handlerFromParent === null) {\n          throw new Error(\n            'withRequestsMadeViaParent() can only be used when the parent injector also configures HttpClient',\n          );\n        }\n        return handlerFromParent;\n      },\n    },\n  ]);\n}\n\n/**\n * Configures the current `HttpClient` instance to make requests using the fetch API.\n *\n * Note: The Fetch API doesn't support progress report on uploads.\n *\n * @see [Advanced fetch Options](guide/http/making-requests#advanced-fetch-options)\n *\n * @publicApi\n * @deprecated `withFetch` is not required anymore. `FetchBackend` is the default `HttpBackend`.","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/common/http/src/provider.ts#L272-L308","documentation":"Thrown by the HttpBackend factory registered withRequestsMadeViaParent() when inject(HttpHandler, {skipSelf: true, optional: true}) returns null — i.e. no ancestor injector provides HttpHandler. The feature's whole contract is 'route this injector's requests through the parent's HTTP stack', so a missing parent configuration is a wiring error, not a runtime condition to recover from.","triggerScenarios":"Using provideHttpClient(withRequestsMadeViaParent()) in a component/route whose injector chain (component tree or environment injector chain) never calls provideHttpClient; placing it in the root config where there is no parent; using it in a standalone bootstrap that also dropped the root HTTP config.","commonSituations":"Copying a lazy-route snippet into app.config.ts; refactoring the root provideHttpClient away (e.g. into a feature) while the child delegation remains; using TestBed where the parent injector has no HTTP providers.","solutions":["Provide HttpClient in the parent injector — e.g. keep provideHttpClient(withFetch(), …) in app.config.ts and use withRequestsMadeViaParent() only in lazy routes/components below it","If there is no parent to delegate to, replace withRequestsMadeViaParent() with a normal provideHttpClient(...) with the backend/interceptors you need","In unit tests, add the parent providers via TestBed.configureTestingModule({providers: [provideHttpClient()]});","Check that you didn't accidentally put withRequestsMadeViaParent() in the root environment config"],"exampleFix":"// before — child delegates but nobody above configures HttpClient\n// app.config.ts has NO provideHttpClient\n@Component({providers: [provideHttpClient(withRequestsMadeViaParent())]})\nclass Widget {}\n\n// after — parent (root) owns the stack, child reuses it\n// app.config.ts:\nproviders: [provideHttpClient(withFetch(), withInterceptors([authInterceptor]))]\n// widget providers:\nproviders: [provideHttpClient(withRequestsMadeViaParent())]","handlingStrategy":"validation","validationCode":"function parentHttpConfigExists(): boolean {\n  return inject(HttpHandler, {skipSelf: true, optional: true}) !== null;\n}\n// inside a provider/initializer in the child injector:\nif (!parentHttpConfigExists()) {\n  throw new Error('withRequestsMadeViaParent() used without a parent provideHttpClient()');\n}","typeGuard":null,"tryCatchPattern":"try {\n  bootstrapApplication(AppComponent, appConfig); // HttpBackend factory throws here on first injection\n} catch (err) {\n  if ((err as Error).message.includes('withRequestsMadeViaParent')) {\n    // add provideHttpClient(...) to the parent injector's providers and retry\n  } else throw err;\n}","preventionTips":["Always pair a child's withRequestsMadeViaParent() with a root provideHttpClient(...) in app.config.ts","In unit tests, configure the parent with TestBed.configureTestingModule({providers: [provideHttpClient(), withRequestsMadeViaParent()]}) ordering","Never put withRequestsMadeViaParent() in the root environment config — there is no parent there"],"tags":["http","dependency-injection","injector-hierarchy","configuration"],"backgroundTag":"missing-di-provider","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}