Installation
RxJS is available as therxjs package on npm. This guide will walk you through different installation methods and show you how to import RxJS into your project.
Package Manager Installation
Current Version: RxJS 8.0.0-alpha.14RxJS 8 is the latest version with improved performance, better modularity, and cleaner TypeScript types.
Verify installation
Check that RxJS was installed correctly by looking at your
package.json:package.json
Import RxJS in your code
You’re ready to start using RxJS! See the import section below for details.
CDN Installation
For quick prototyping or experiments, you can use RxJS directly from a CDN without any build setup.CDN imports are great for learning and quick experiments, but for production applications, we recommend using a package manager and bundler for better performance and tree-shaking.
Importing RxJS
RxJS uses ES modules and provides a clean import structure. Here’s how to import different parts of the library:Core Imports
Main exports
Operators
Operators are available from the mainrxjs package:
Operators
Specialized Modules
RxJS provides specialized entry points for different functionality:Complete Import Example
Here’s a real-world example showing typical imports:app.ts
TypeScript Configuration
RxJS 8 requires TypeScript 4.2 or higher for full type support.tsconfig.json
Module Formats
RxJS 8 provides multiple module formats to support different environments:ESM (Default)
Modern ES modules for bundlers and modern browsers
CommonJS
For Node.js and older build systems
Tree Shaking
RxJS is fully tree-shakeable, meaning unused operators and functions will be removed from your final bundle.RxJS 8 has
"sideEffects": false in its package.json, ensuring optimal tree-shaking with all modern bundlers.Troubleshooting
Module not found errors
Module not found errors
If you see errors like
Cannot find module 'rxjs', ensure:- You’ve run the install command (
npm install rxjs) - Your
node_modulesfolder exists - Try deleting
node_modulesandpackage-lock.jsonand reinstalling
TypeScript type errors
TypeScript type errors
Ensure you’re using TypeScript 4.2 or higher:
Import path issues
Import path issues
Always import from
rxjs or specific entry points:Next: Build your first Observable
Now that RxJS is installed, let’s create your first reactive application
