使用Webpack构建Angular 2应用程序时出现以下错误:
未找到
./~/@angular/core/bundles/core.umd.js
模块中的错误:错误无法解析模块' rxjs / Subject'在
C:\...\node_modules\@angular\core\bundles
@
./~/@angular/core/bundles/core.umd.js
7:84-107
这是我的package.json:
...
"devDependencies": {
"ts-loader": "^1.3.3",
"typescript": "~2.0.10",
"webpack": "^1.14.0"
},
"dependencies": {
"@angular/common": "~2.4.0",
"@angular/compiler": "~2.4.0",
"@angular/core": "~2.4.0",
"@angular/forms": "~2.4.0",
"@angular/http": "~2.4.0",
"@angular/platform-browser": "~2.4.0",
"@angular/platform-browser-dynamic": "~2.4.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.9",
"rxjs": "^5.0.1",
"zone.js": "^0.7.4"
}
}
我的webpack.config.js
:
module.exports = {
entry: './src/modules/app/main.ts',
output: {
path: './src/dist/',
filename: 'bundle.js'
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts']
},
module: {
loaders: [
{
exclude: /node_modules/,
test: /\.ts?$/,
loader: 'ts-loader'
}
]
}
}
请注意,我的Angular 2应用程序位于/src/modules/app/main.ts
文件夹中。
为什么Webpack无法解析RxJS
依赖项?
答案 0 :(得分:3)
我认为您在.js
内部对于webpack配置缺少resolve
扩展名,因此您Module not found
获得了core.umd.js
:
resolve: {
extensions: ['', '.js' , '.webpack.js', '.web.js', '.ts']
}
答案 1 :(得分:1)
您需要导入主题:
import { Subject } from 'rxjs/Subject';