5

我最近安装了 Angular 4 (RC2) 并从简单的快速入门示例中复制了文件。但是当我尝试使用 Webpack 构建项目时,我收到错误消息,指出无法解析 Rxjs:

WARNING in ~/@angular/core/@angular/core.es5.js
6857:19-40 Critical dependency: the request of a dependency is an expression

WARNING in ~/@angular/core/@angular/core.es5.js
6883:19-106 Critical dependency: the request of a dependency is an expression

ERROR in ~/@angular/core/@angular/core.es5.js
Module not found: Error: Can't resolve 'rxjs/Subject' in 'node_modules/@angular/core/@angular'
 @ ~/@angular/core/@angular/core.es5.js 26:0-39
 @ ./app/app.module.ts
 @ ./main.ts

ERROR in ~/@angular/core/@angular/core.es5.js
Module not found: Error: Can't resolve 'rxjs/observable/merge' in 'node_modules/@angular/core/@angular'
 @ ~/@angular/core/@angular/core.es5.js 23:0-46
 @ ./app/app.module.ts
 @ ./main.ts

ERROR in ~/@angular/core/@angular/core.es5.js
Module not found: Error: Can't resolve 'rxjs/operator/share' in 'node_modules/@angular/core/@angular'
 @ ~/@angular/core/@angular/core.es5.js 24:0-44
 @ ./app/app.module.ts
 @ ./main.ts

ERROR in ~/@angular/core/@angular/core.es5.js
Module not found: Error: Can't resolve 'rxjs/symbol/observable' in 'node_modules/@angular/core/@angular'
 @ ~/@angular/core/@angular/core.es5.js 25:0-54
 @ ./app/app.module.ts
 @ ./main.ts

ERROR in ~/@angular/core/@angular/core.es5.js
Module not found: Error: Can't resolve 'rxjs/Observable' in 'node_modules/@angular/core/@angular'
 @ ~/@angular/core/@angular/core.es5.js 22:0-45
 @ ./app/app.module.ts
 @ ./main.ts

我已经安装了 Rxjs 5.0.1,我认为这是 Angular 所期望的版本。我想不出还有什么可做的。

4

2 回答 2

7

new ContextReplacementPlugin( /angular(\\|\/)core(\\|\/)@angular/, path.resolve(__dirname, '../src') ) 适用于 webpack.common.js 中的 webpack

于 2017-03-10T10:53:32.090 回答
0

在此配置下工作没有问题:

new webpack.ContextReplacementPlugin(
  /angular(\\|\/)core(\\|\/)@angular/,/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
  helpers.root('../src'), 
  {} 
),

确保在 helpers.root 上有两个点,而不是一个。('../src')

于 2017-05-12T09:27:12.030 回答