You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular学习遇RxJS报错:../node_modules/rxjs/Rx无导出成员'of'

Fixing the RxJS 'of' Export Error in Angular

Hey there! I see you’re working through the Angular tutorial and ran into that annoying "'../node_modules/rxjs/Rx"' has no exported member 'of'" error. Let’s fix this quickly.

The Root Cause

You’re importing of from the wrong path! In RxJS 6 and later (which is what modern Angular versions use), creation operators like of aren’t exported from rxjs/Observable anymore. That path is only for the Observable class itself now—all the handy operators live directly in the root rxjs package.

The Fix

Swap out your import line for the correct one. You already have the right line commented out—just uncomment it and remove the incorrect import:

// Replace this:
// import { Observable, of } from 'rxjs/Observable';

// With this:
import { Observable, of } from 'rxjs';

Here’s What Your Updated hero.service.ts Should Look Like

import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
import { MessageService } from './message.service';

@Injectable({
  providedIn: 'root'
})
export class HeroService {
  constructor(private messageService: MessageService) { }

  getHeroes(): Observable<Hero[]> {
    this.messageService.add('HeroService: fetched heroes');
    return of(HEROES);
  }
}

This change aligns with RxJS 6’s modular structure, which was designed to make imports cleaner and tree-shaking more effective. Once you update the import, your app should run without that error.

内容的提问来源于stack exchange,提问作者arun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:07:37