不能用Webpack构建角度4的例子?

时间:2022-12-05 23:28:01

I recently installed Angular 4 (RC2) and copied the files from the simple Quickstart example. But when I try to build the project with Webpack, I get errors stating that Rxjs can't be resolved:

我最近安装了角4 (RC2),并从简单的Quickstart示例中复制了这些文件。但是,当我尝试使用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

I've installed Rxjs 5.0.1, which I think is the version that Angular is expecting. I can't think of anything else to do.

我已经安装了Rxjs 5.0.1,我认为这是angle期待的版本。我想不出别的办法了。

2 个解决方案

#1


7  

new ContextReplacementPlugin( /angular(\\|\/)core(\\|\/)@angular/, path.resolve(__dirname, '../src') ) Works for me for webpack in webpack.common.js

新ContextReplacementPlugin(/角(\ \ | \ /)核心(\ \ | \ /)@angular /路径。resolve(__dirname, '. /src')对我在webpack.common.js中的webpack适用

#2


0  

work with no problems under this configuration:

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

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

make sure on helpers.root have two dots, not one. ('../src')

确保在帮手。根有两个点,不是一个。(“. . / src”)

#1


7  

new ContextReplacementPlugin( /angular(\\|\/)core(\\|\/)@angular/, path.resolve(__dirname, '../src') ) Works for me for webpack in webpack.common.js

新ContextReplacementPlugin(/角(\ \ | \ /)核心(\ \ | \ /)@angular /路径。resolve(__dirname, '. /src')对我在webpack.common.js中的webpack适用

#2


0  

work with no problems under this configuration:

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

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

make sure on helpers.root have two dots, not one. ('../src')

确保在帮手。根有两个点,不是一个。(“. . / src”)