RxJS: TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.
An RxJS operator (switchMap, mergeMap, forkJoin, subscribe) received undefined — a function forgot to return an Observable.
You provided 'undefined' where a stream was expectedYou provided 'undefined' where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.TypeError: You provided an invalid object where a stream was expectedYou provided 'null' where a stream was expected Meaning
Operators like switchMap(x => this.load(x)) must return an Observable. If the inner function has curly braces without a return, or a service method is undefined (typo, injection missing), the operator gets undefined. Mocks in tests that return nothing cause the same error.
Common causes
- Arrow function with
{ }and noreturninsideswitchMap/mergeMap - Service method or property is
undefined(typo, wrong injection) - Test mock returns
undefinedinstead ofof(...) forkJoinarray containing an undefined entry- Conditional branch returning nothing
⚡ Quick fix
- Return an Observable from every branch (
return of(null)) - Use an arrow expression without braces
- In tests mock with
of(value)orjasmine.createSpy().and.returnValue(of(...))
Detailed fix by platform
Angular
switchMap(id => this.api.load(id))(no braces) orswitchMap(id => { return this.api.load(id); })- Provide mocks:
{ provide: Api, useValue: { load: () => of(item) } }
Code examples
Always return a stream
this.route.paramMap.pipe(
map(p => p.get('id')),
switchMap(id => id ? this.api.load(id) : of(null)), // both branches return an Observable
).subscribe(item => (this.item = item));How to diagnose
- Operator — Which operator raised it?
- Return — Does the callback return an Observable?
- Mock — Does the test double return one?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Cannot find control with name Angular: Error: Cannot find control with name: 'email' (reactive forms)
- EmptyError RxJS: EmptyError: no elements in sequence (firstValueFrom / lastValueFrom on an empty Observable)
- exceeded maximum budget Angular build: Error: bundle initial exceeded maximum budget. Budget 1.00 MB was not met by 120.00 kB with a total of 1.12 MB
Most viewed in Angular
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026