无法导入Angular 6中的某些模块

时间:2018-11-27 18:43:22

标签: angular import rxjs observable

尝试以角度6导入一些可观察的模块。 这是我要导入的模块:

import { BehaviorSubject } from "rxjs/BehaviorSubject";
import { observable } from "rxjs/Rx";
import { of } from "rxjs/observable/of";

我收到此错误:

    ERROR in node_modules/rxjs/BehaviorSubject.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/BehaviorSubject'.
node_modules/rxjs/Rx.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat'.
node_modules/rxjs/observable/of.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/observable/of'.
src/app/services/log.service.ts(3,10): error TS2305: Module '"C:/Users/mendi/OneDrive/Desktop/Websites/training/Udemy Course angular/sandbox/devlogger/node_modules/rxjs/BehaviorSubject"' has no exported member 'BehaviorSubject'.
src/app/services/log.service.ts(4,10): error TS2305: Module '"C:/Users/mendi/OneDrive/Desktop/Websites/training/Udemy Course angular/sandbox/devlogger/node_modules/rxjs/Rx"' has no exported member 'Observable'.
src/app/services/log.service.ts(5,10): error TS2305: Module '"C:/Users/mendi/OneDrive/Desktop/Websites/training/Udemy Course angular/sandbox/devlogger/node_modules/rxjs/observable/of"' has no exported member 'of'.

ERROR in node_modules/rxjs/BehaviorSubject.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/BehaviorSubject'.
node_modules/rxjs/Rx.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat'.
node_modules/rxjs/observable/of.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/observable/of'.
src/app/services/log.service.ts(3,10): error TS2305: Module '"C:/Users/mendi/OneDrive/Desktop/Websites/training/Udemy Course angular/sandbox/devlogger/node_modules/rxjs/BehaviorSubject"' has no exported member 'BehaviorSubject'.
src/app/services/log.service.ts(4,10): error TS2305: Module '"C:/Users/mendi/OneDrive/Desktop/Websites/training/Udemy Course angular/sandbox/devlogger/node_modules/rxjs/Rx"' has no exported member 'Observable'.
src/app/services/log.service.ts(5,10): error TS2305: Module '"C:/Users/mendi/OneDrive/Desktop/Websites/training/Udemy Course angular/sandbox/devlogger/node_modules/rxjs/observable/of"' has no exported member 'of'.

有关我的版本的一些信息:

Angular CLI: 6.0.8
Node: 8.11.1
OS: win32 x64
Angular: 6.1.10    

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.3.3
typescript                        2.7.2
webpack                           4.8.3

无法编译。

我该怎么办?

1 个答案:

答案 0 :(得分:1)

尝试

import { BehaviorSubject, Observable, of } from "rxjs";