You provided 'undefined' where a stream was expected Angular Origin: On your device Last updated 15 Oct 2026

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.

Exact message you may see 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
Seen on: Angular TypeScript

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 no return inside switchMap / mergeMap
  • Service method or property is undefined (typo, wrong injection)
  • Test mock returns undefined instead of of(...)
  • forkJoin array containing an undefined entry
  • Conditional branch returning nothing

⚡ Quick fix

  1. Return an Observable from every branch (return of(null))
  2. Use an arrow expression without braces
  3. In tests mock with of(value) or jasmine.createSpy().and.returnValue(of(...))

Detailed fix by platform

Angular

  1. switchMap(id => this.api.load(id)) (no braces) or switchMap(id => { return this.api.load(id); })
  2. Provide mocks: { provide: Api, useValue: { load: () => of(item) } }

Code examples

Always return a stream

typescript
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

  1. Operator — Which operator raised it?
  2. Return — Does the callback return an Observable?
  3. 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:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Cannot find control with name — Angular: Error: Cannot find control with name: 'email' (reactive forms) (Angular)Cannot find control w…EmptyError — RxJS: EmptyError: no elements in sequence (firstValueFrom / lastValueFrom on an empty Observable) (Angular)EmptyErrorexceeded 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 (Angular)exceeded maximum budg…NG02100 — Angular: NG02100: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe' (Angular)NG02100NullInjectorError: No provider for HttpClient! — Angular: NullInjectorError: No provider for HttpClient! — provideHttpClient() missing (Angular)NullInjectorError: No…reading length — TypeError: Cannot read properties of undefined (reading 'length') (JavaScript)reading lengthSchema validation failed with the following errors — Angular CLI: Schema validation failed with the following errors: Data path "" must NOT have additional properties(xyz) (Angular)Schema validation fai…You provi…

Explore the map of this error Full error map →

🧠 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.