I encountered an issue while attempting to run a basic TypeScript project using webpack 3 and rxjs5.
app.ts :
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
const myObservable: any = Observable.of(1, 2, 3)
.subscribe(
(value: any) => console.log(value),
(err: any) => console.log(err),
() => console.log("Streaming is over")
);
index.html :
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Webpack 3 with Typescript</title>
</head>
<body>
<h1>Let's learn Webpack 3</h1>
<script src="dist/bundle.js"></script>
</body>
</html>
package.json :
{
"name": "ObservablesProject2",
"version": "1.0.0",
...
}
tsconfig.json :
{
"compilerOptions": {
/* Basic Options */
...
},
"exclude": [
"node_modules"
]
}
webpack.config.js :
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './src/js/app.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/dist'
},
module: {
rules: [
...
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
// ...
})
]
};
An error message I received during compilation:
ERROR in ./src/js/app.ts
[tsl] ERROR in /Users/administrator/WebstormProjects/ObservablesProject2/src/js/app.ts(1,28)
TS7016: Could not find a declaration file for module 'rxjs/Observable'. '/Users/administrator/WebstormProjects/ObservablesProject2/node_modules/rxjs/Observable.js' implicitly has an 'any' type.
Try `npm install @types/rxjs/Observable` if it exists or add a new declaration (.d.ts) file containing `declare module 'rxjs/Observable';`