升级到 Angular 10 - 修复 CommonJS 或 AMD 依赖项可能导致优化救助 [英] Upgrading to Angular 10 - Fix CommonJS or AMD dependencies can cause optimization bailouts

查看:15
本文介绍了升级到 Angular 10 - 修复 CommonJS 或 AMD 依赖项可能导致优化救助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 angular 9 应用程序升级到 angular 10 版本,但在升级后低于警告

I am trying to upgrade my angular 9 app to angular 10 version, but getting below warning after the upgrade

rxjsBehaviorSubject.js depends on rxjs-compat/BehaviorSubject

知道如何解决这个问题吗?

Any idea how to fix this?

推荐答案

当您使用随 CommonJS 打包的依赖项时,可能会导致 更大更慢的应用程序

When you use a dependency that is packaged with CommonJS, it can result in larger slower applications

从版本 10 开始,Angular 现在会在您的构建引入这些包之一时向您发出警告.如果您已经开始看到这些依赖项的警告,请让您的依赖项知道您更喜欢 ECMAScript 模块 (ESM) 包.

Starting with version 10, Angular now warns you when your build pulls in one of these bundles. If you’ve started seeing these warnings for your dependencies, let your dependency know that you’d prefer an ECMAScript module (ESM) bundle.

这是官方文档 - 配置 CommonJS 依赖项

在您的 angular.json 文件中查找构建对象并添加

In your angular.json file look for the build object and add

allowedCommonJsDependencies

allowedCommonJsDependencies

如下图-

"build": {
  "builder": "@angular-devkit/build-angular:browser",
  "options": {
     "allowedCommonJsDependencies": [
        "rxjs-compat",
         ... few more commonjs dependencies ... 
     ]
     ...
   }
   ...
},

这篇关于升级到 Angular 10 - 修复 CommonJS 或 AMD 依赖项可能导致优化救助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆