RxJS: EmptyError: no elements in sequence (firstValueFrom / lastValueFrom on an empty Observable)
firstValueFrom, lastValueFrom, first() or last() waited for a value but the Observable completed without emitting.
EmptyError: no elements in sequenceno elements in sequenceEmptyError: no elements in sequence firstValueFrom Meaning
These helpers reject with EmptyError when the source completes empty (an empty array in from([]), a filter that dropped everything, an HTTP call returning EMPTY). Provide a default ({ defaultValue: null }), use take(1) with defaultIfEmpty, or handle the empty case explicitly.
Common causes
- Source completed without emitting (filtered out, empty list,
EMPTY) firstValueFromused on a Subject that completes firstfirst()after afilterthat matches nothing- Error handling returning
EMPTY - Route guard or resolver relying on a value that never arrives
⚡ Quick fix
- Pass a default:
firstValueFrom(obs$, { defaultValue: null }) - Use
defaultIfEmpty(null)before the helper - Catch the error and handle emptiness
Detailed fix by platform
Angular
const user = await firstValueFrom(user$.pipe(defaultIfEmpty(null)));- Prefer
take(1)without throwing on empty:user$.pipe(take(1)).subscribe(...)
Code examples
Safe first value
import { defaultIfEmpty, firstValueFrom } from 'rxjs';
const first = await firstValueFrom(this.items$.pipe(defaultIfEmpty(null))); // null instead of EmptyErrorHow to diagnose
- Source — Does the Observable emit before completing?
- Operators — filter/EMPTY upstream?
- Helper — Is a default value provided?
🔧 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)
- Could not find the builder's node package Angular CLI: Could not find the '@angular-devkit/build-angular:browser' builder's node package / Cannot find module '@angular-devkit/build-angular/package.json'
- 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