【发布时间】:2018-10-03 17:03:38
【问题描述】:
我在部署时不断收到这些警告:
WARNING in ./node_modules/@angular/core/fesm5/core.js
4996:15-36 Critical dependency: the request of a dependency is an expression
@ ./node_modules/@angular/core/fesm5/core.js
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/main.ts
WARNING in ./node_modules/@angular/core/fesm5/core.js
5008:15-102 Critical dependency: the request of a dependency is an expression
@ ./node_modules/@angular/core/fesm5/core.js
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/main.ts
我尝试过的:
https://github.com/angular/angular/issues/20357
我的项目结构:
我的 webpack.config.js:
var path = require('path');
plugins: [
new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)esm5/, path.join(__dirname, './src')),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
inject: 'body'
}),
new webpack.DefinePlugin({
// global app config object
config: JSON.stringify({
apiUrl: 'http://localhost:4000'
})
})
],
【问题讨论】:
-
您是否尝试在上面发布的
webpack.config.js中将[...]esm5/更改为[...]fesm5/? -
这行得通,如果您将此作为答案发布,我会接受。你能解释一下为什么这行得通而前者不行吗?
-
误会了,我在angular 7中遇到这个,webpack不再直接配置了。想说遇到这个,但是没办法配置。但是作为旁注,ng 8 中支持的方式是使用
ngx-build-plusnpm 模块来覆盖/扩展基本 webpack 配置。