2016-12-19 9 views
0

非常にTypescriptアプリがあり、rxjsを使いたいです。TypeScriptアプリケーション内でrxjs演算子を使用する方法

私がやった:

ファイルmain.tsで、その後
npm install --save-dev rxjs 

を:使用して、here is my gulpfile:あなたが必要な場合には

Module not found: Error: Cannot resolve module 'rxjs/add/observable/from' 

import { Observable } from 'rxjs/Observable'; 
import 'rxjs/add/observable/from'; 
import 'rxjs/add/operator/filter'; 

function test() { 
    Observable.from([0,1,2,3,4]) 
    .filter((x) => x >= 2) 
    .subscribe((x) => console.log(x)); 
} 

私はコンパイルエラーを取得しますウェブパック

私は何が欠けているか知っていますか? ありがとうございました

+0

'typescript'と' rxjs'のバージョンを確認できますか?これはうまくいくはずです... – martin

+0

typescript:2.0.9、rxjs:5.0.1 –

+0

これはwebpackなしで動作しますので、これはtypecriptとは関係ないのでwebpackの設定を見てください – martin

答えて

3

解決可能な拡張機能を追加しなかったwebpack.config.jsを確認していました。

のWebPACKは言う、

An array of extensions that should be used to resolve modules. For example, in order to discover CoffeeScript files, your array should contain the string ".coffee".

Default: [".webpack.js", ".web.js", ".js"]

IMPORTANT: Setting this option will override the default, meaning that webpack will no longer try to resolve modules using the default extensions. If you want modules that were required with their extension (e.g. require('./somefile.ext')) to be properly resolved, you must include an empty string in your array. Similarly, if you want modules that were required without extensions (e.g. require('underscore')) to be resolved to files with “.js” extensions, you must include ".js" in your array.

あなたはWebPACKののデフォルトの解決拡張オプションを上書きしているので、あなたが['.js', '.ts', '']拡張子を持つモジュールを解決してください、WebPACKのを伝える必要があります。

関連する問題