无法加载 RxJs

Can not load RxJs

我在组件文件之一中使用此导入语句:

import {BehaviorSubject} from 'rxjs';
@Injectable()
export class UserService {
    private currentUser = new BehaviorSubject<User>(null);
}

当浏览器加载应用程序时,抛出以下异常:

SyntaxError: Unexpected token <
Evaluating http://localhost:3000/rxjs
Error loading http://localhost:3000/app/components/app.js
at eval (native)
at SystemJSLoader.__exec (http://localhost:3000/vendors.js:3320:16)

我不知道为什么它不起作用。因为 Angular2 已经工作了。 任何人都可以帮我解决这个问题吗?

我认为这与 Gulp 的串联无关,但与您使用的模块有关。

您应该使用以下其中一项:

import {BehaviorSubject} from 'rxjs/Rx';

import {BehaviorSubject} from 'rxjs/subject/BehaviorSubject';

事实上,RxJS 并不直接注册一个 rxjs 模块,而是注册子模块(类似于 rxjs/something)。因此 SystemJS 找不到以前注册的模块,因此它尝试从地址 http://localhost:3000/rxjs 加载,但返回 404 错误...