【问题标题】:Angular - primeng CommonJS or AMD dependencies can cause optimization bailoutsAngular - 启动 CommonJS 或 AMD 依赖项可能导致优化救助
【发布时间】:2020-11-30 02:57:23
【问题描述】:

我有一个小的 Angular 应用程序,我在其中使用 PrimeNG components。 由于我进行了 Angular 10 更新,我收到以下警告:

CommonJS 或 AMD 依赖项可能导致优化救助。

针对不同的 PirmeNg 组件。

我已经试过了:

"allowedCommonJsDependencies": [
              "loadsh",
              "primeng/primeng",
              "primeicons",

这是offical homepage上的建议

我做的另一个尝试是检查 this post 中提到的导入

import { x } from '@auth/auth....'           // Warning
...to...
import { x } from '../auth/...'              // Warning goes away

但由于我没有任何开头带有“@”的导入,我想知道如何修复或抑制此警告?

编辑:

详细错误:

“路径”中的警告取决于“chartjs”。 CommonJS 或 AMD 依赖项 可能会导致优化救助。

【问题讨论】:

  • @Jason Aller 你能分享一下你在构建中看到的确切警告信息吗?
  • @GunjanKhanwilkar 我没有问这个问题,我只是编辑了它。您想将您的评论指向 Felix。
  • @Felix 您能否分享您在构建中看到的确切警告消息?
  • @GunjanKhanwilkar 我添加了警告作为编辑。 'path' 是使用的库的 excat 文件
  • @FelixGerber 然后你只需要添加 - "allowedCommonJsDependencies": [ "loadsh", "primeng/primeng", "primeicons", "chartjs" ] 在现有列表中添加chartjs,就像上面一样很好。有关详细说明,请在此处查看此答案-stackoverflow.com/a/62604034/6097025

标签: angular primeng angular10


【解决方案1】:

你只需要添加 -

    "allowedCommonJsDependencies": [ 
    "loadsh", 
    "primeng/primeng", 
    "primeicons", 
    "chartjs", 
    ---etc--- all the CommonJs dependency goes here to suppress warning!    
] 

只需添加

图表

在您现有的上述列表中,您很好。 有关详细说明,请在此处查看此答案-https://stackoverflow.com/a/63430362/6097025

请注意,这只是抑制警告的一种解决方法!如果你想完全解决这个问题,那么你需要为你的依赖项导入 ES-6 模块并避免 CommonJs 依赖项。 Angular-10 及更高版本现在显示这些警告以进行构建优化。

【讨论】:

    【解决方案2】:

    在 angular.json 中添加

     "build": {
              "builder": "@angular-devkit/build-angular:browser",
              "options": {
                "allowedCommonJsDependencies": ["chart.js"],
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 2020-10-16
      • 2020-10-16
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多