繁体   English   中英

使用WebPack构建Angular 2时RxJS解决错误

[英]RxJS Resolve Error When Building Angular 2 with WebPack

使用Webpack构建Angular 2应用程序时出现以下错误:

./~/@angular/core/bundles/core.umd.js找不到错误:错误

无法解析C:\\...\\node_modules\\@angular\\core\\bundles模块'rxjs / Subject'

@ ./~/@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依赖关系?

我认为您在resolve Webpack配置的过程中缺少.js扩展名,因此,您得到的Module not found core.umd.js

resolve: {
    extensions: ['', '.js' , '.webpack.js', '.web.js', '.ts']
}

您需要导入主题:

import { Subject } from 'rxjs/Subject';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM