# RxJS: EmptyError: no elements in sequence (firstValueFrom / lastValueFrom on an empty Observable)

**Code:** `EmptyError` · **Category:** Angular · **Seen on:** Angular, TypeScript

`firstValueFrom`, `lastValueFrom`, `first()` or `last()` waited for a value but the Observable completed without emitting.

## 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`)
- `firstValueFrom` used on a Subject that completes first
- `first()` after a `filter` that matches nothing
- Error handling returning `EMPTY`
- Route guard or resolver relying on a value that never arrives

## Quick fix

1. Pass a default: `firstValueFrom(obs$, { defaultValue: null })`
2. Use `defaultIfEmpty(null)` before the helper
3. Catch the error and handle emptiness

## Detailed fix by platform

### Angular

1. `const user = await firstValueFrom(user$.pipe(defaultIfEmpty(null)));`
2. Prefer `take(1)` without throwing on empty: `user$.pipe(take(1)).subscribe(...)`

## Code examples

### Safe first value

```typescript
import { defaultIfEmpty, firstValueFrom } from 'rxjs';

const first = await firstValueFrom(this.items$.pipe(defaultIfEmpty(null)));   // null instead of EmptyError
```

## How to diagnose

1. **Source** — Does the Observable emit before completing?
2. **Operators** — filter/EMPTY upstream?
3. **Helper** — Is a default value provided?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/angular/rxjs-empty-error-no-elements-in-sequence)
