Reputation: 1310
I'm trying to get rxjs to work within a typescript/webpack set up but after following the installation guide and starting up the webpack dev server it says it cannot find the module. I've looked around but can't seem to anything that can point me to a solution for my problem.
Just to clarify I've run the following commands npm install rxjs-es @types/es6-shim --save
.
To set up typescript/webpack bundle, I referred to their 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',
};
index
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));
Error message:
I've tried using both rxjs
and rxjs-es
packages, and renaming the import to rxjs-es/Rx
Not sure if I'm missing something here, as it was very simple to install d3.js in comparison to this.
If you need any more info please say, any help is much appreciated, cheers!
Upvotes: 1
Views: 843
Reputation: 40328
What worked for me:
I started with the setup you describe, BUT changed the following:
@types/es6-shim
"moduleResolution": "node"
to tsconfig.jsonaltered the import statement in index.ts
as:
import * as Rx from 'rxjs';
...and it worked, both from within VSCode and from Webpack.
Upvotes: 1