首页 > 解决方案 > 使用 SSR 调试 Angular 6 Universal

问题描述

Angular 6 正在使用 Universal SSR,但它占用了我的服务器资源。构建 PROD 时,我有以下警告。

WARNING in ./node_modules/bindings/bindings.js
81:22-40 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/bindings/bindings.js
 @ ./node_modules/utf-8-validate/index.js
 @ ./node_modules/ws/lib/validation.js
 @ ./node_modules/ws/lib/receiver.js
 @ ./node_modules/ws/index.js
 @ ./server.ts

WARNING in ./node_modules/bindings/bindings.js
81:43-53 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/bindings/bindings.js
 @ ./node_modules/utf-8-validate/index.js
 @ ./node_modules/ws/lib/validation.js
 @ ./node_modules/ws/lib/receiver.js
 @ ./node_modules/ws/index.js
 @ ./server.ts

WARNING in ./node_modules/@angular/core/fesm5/core.js
System.import() is deprecated and will be removed soon. Use import() instead.
For more info visit https://webpack.js.org/guides/code-splitting/
 @ ./server.ts 5560:15-36 7:13-37

WARNING in ./node_modules/@angular/core/fesm5/core.js
System.import() is deprecated and will be removed soon. Use import() instead.
For more info visit https://webpack.js.org/guides/code-splitting/
 @ ./server.ts 5572:15-102 7:13-37

你遇到过这些吗?我怎么能摆脱这些?

标签: angularwarningsangular6angular-universalserver-side-rendering

解决方案


我相信您可以通过在“webpack.server.config.js”文件中添加以下内容来解决此问题:

...
plugins: [
    // Temporary Fix for issue: https://github.com/angular/angular/issues/11580
    // for 'WARNING Critical dependency: the request of a dependency is an expression'
    new webpack.ContextReplacementPlugin(
      /(.+)?angular(\\|\/)core(.+)?/,
      path.join(__dirname, 'src'), // location of your src
      {} // a map of your routes
    ),
    new webpack.ContextReplacementPlugin(
      /(.+)?express(\\|\/)(.+)?/,
      path.join(__dirname, 'src'),
      {}
    )
  ]
...


推荐阅读