1. 程式人生 > >webpack rxjs 6+ 引入模組報錯

webpack rxjs 6+ 引入模組報錯


環境

webpack 4.14.0

typescript 3.0.1

rxjs 6.3.3

 

第一種引入方式
var Observable = require('rxjs/Observable').Observable;
// patch Observable with appropriate methods
報錯:
Module not found: Error: Can't resolve 'rxjs-compat' in 'D:\project\ztEditor\node_modules\rxjs'

第二種引入方式
import { Observable} from 'rxjs/Observable';
報錯
TS2305: Module '"D:/project/ztEditor/node_modules/rxjs/Observable"' has no exported member 'Observable'.

 正確的引入方式
import { Observable, Subject, ReplaySubject, from, of, range } from 'rxjs';
import { map, filter, switchMap } from 'rxjs/operators';