RxJS: Reactive Extensions For JavaScript
RxJS (Reactive Extensions for JavaScript) is a library for reactive programming using Observables, making it easier to compose asynchronous or callback-based code sequences. The current stable version is 7.8.2, with an active roadmap towards version 8, including regular alpha releases and maintenance updates.
Common errors
-
Module not found: Can't resolve 'rxjs/operators'
cause Attempting to import operators from 'rxjs/operators' in RxJS version 7.2 or later.fixImport operators directly from 'rxjs' instead, e.g., `import { map } from 'rxjs';`. -
TypeError: Subject.create is not a function
cause Calling the `create` static method on `Subject` in RxJS v8 or later.fixInstantiate `Subject` directly using its constructor: `const subject = new Subject();`. -
TypeError: Cannot read properties of undefined (reading 'subscribe')
cause An Observable was created but its `subscribe()` method was not called, preventing it from executing.fixEnsure `observable.subscribe()` is called to activate the Observable and start emitting values. -
Property 'pipe' does not exist on type 'Observable<any>'
cause Attempting to use an operator directly on an Observable instance without using the `.pipe()` method.fixWrap your operators within a `.pipe()` call: `observable.pipe(operator1(), operator2()).subscribe(...)`.
Warnings
- breaking The `Symbol.observable` export has been removed.
- breaking The deprecated `Subject.create` method has been removed.
- breaking `WebSocketSubject` no longer extends `Subject`.
- gotcha Operator import paths changed in RxJS 7.2.
Install
-
npm install rxjs -
yarn add rxjs -
pnpm add rxjs
Imports
- range, filter, map
import { filter, map } from 'rxjs/operators';import { range, filter, map } from 'rxjs';
Quickstart
import { range, filter, map } from 'rxjs';
range(1, 200)
.pipe(
filter(x => x % 2 === 1),
map(x => x + x)
)
.subscribe(x => console.log(x));