使用typescript / webpack build时找不到rxjs模块

时间:2017-05-29 10:17:53

标签: typescript webpack rxjs

我试图让rxjs在一个打字稿/ webpack设置中工作,但是在关注installation guide并启动webpack开发服务器之后,它说它无法找到该模块。我环顾四周,但似乎没有什么可以指出我解决问题的方法。

只是为了澄清我运行了以下命令npm install rxjs-es @types/es6-shim --save

要设置typescript / webpack包,我提到了他们的installation guide

tsconfig

{
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "target": "es6",
    "module": "es6",
    "jsx": "react",
    "allowJs": true
  }
}

webpack config

module.exports = {
    entry: './index.ts',
    output: {
        filename: 'bundle.js',
        path: __dirname
    },
    module: {
        rules: [
            {
                enforce: 'pre',
                test: /\.js$/,
                loader: "source-map-loader"
            },
            {
                enforce: 'pre',
                test: /\.tsx?$/,
                use: "source-map-loader"
            }
        ],
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                exclude: /node_modules/,
                use: [ 'babel-loader', 'ts-loader' ]
            }
        ]
    },
    resolve: {
        extensions: [".tsx", ".ts", ".js"]
    },
    devtool: 'inline-source-map',
};

索引

import * as d3 from 'd3';
import Rx from 'rxjs/Rx';


d3.select("body").append("span")
    .text("Hello, world!");

Rx.Observable.of(`Hello World`)
    .subscribe(result => console.log(result));

错误讯息:

enter image description here

我已尝试同时使用rxjsrxjs-es个包,并将导入重命名为rxjs-es/Rx

我不确定此处是否遗漏了某些内容,因为与此相比,安装d3.js非常简单。

如果您需要更多信息请说,任何帮助都非常感谢,欢呼!

1 个答案:

答案 0 :(得分:1)

对我有用的是什么:

我从你描述的设置开始,但改变了以下内容:

  • npm安装了rxjs,而不是rxjs-es
  • (编辑)已删除@types/es6-shim
  • "moduleResolution": "node"添加到tsconfig.json
  • index.ts中的import语句更改为:

    import * as Rx from 'rxjs';
    

......并且它在VSCode和Webpack中都有效。

相关问题