3

I got a little Angular app, in which I'm using PrimeNG components. Since I did the Angular 10 update I get the following Warning:

CommonJS or AMD dependencies can cause optimization bailouts.

for different PirmeNg-components.

I already tried this:

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

This is suggested on the offical homepage

Another try I did is checking the imports like mentioned in this post

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

But as I don't have any imports with "@" on the beginning I'm wondering how this warning could be fixed or suppressed?

EDIT:

Error in detail:

WARNING in 'path' depends on 'chartjs'. CommonJS or AMD dependencies can cause optimization bailouts.

Felix Gerber
  • 1,615
  • 3
  • 30
  • 40
  • @Jason Aller Can you share the exact warning message what you are seeing in your build ? – Gunjan Khanwilkar Aug 15 '20 at 20:20
  • @GunjanKhanwilkar I didn't ask this question, I only edited it. You want to direct your comment to Felix. – Jason Aller Aug 15 '20 at 22:26
  • @Felix Can you share the exact warning message what you are seeing in your build ? – Gunjan Khanwilkar Aug 15 '20 at 23:01
  • @GunjanKhanwilkar i added a the Warning as an Edit. 'path' is the excat file of the used library – Felix Gerber Aug 17 '20 at 09:39
  • @FelixGerber Then you just need to add - "allowedCommonJsDependencies": [ "loadsh", "primeng/primeng", "primeicons", "chartjs" ] Add chartjs in your existing list like above and you are good. For detailed explanation please check this answer here - https://stackoverflow.com/a/62604034/6097025 – Gunjan Khanwilkar Aug 18 '20 at 17:28

2 Answers2

7

In angular.json add

 "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "allowedCommonJsDependencies": ["chart.js"],
Abhishek Patil
  • 1,373
  • 3
  • 30
  • 62
akhilreddy
  • 272
  • 3
  • 6
4

you just need to add -

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

Just Add

chartjs

in your existing list like above and you are good. For detailed explanation please check this answer here - https://stackoverflow.com/a/63430362/6097025

Note that this is just a workaround to suppress warnings! If you want to completely fix this then you need to import ES-6 modules for your dependencies and avoid CommonJs dependencies. Angular-10 onwards now it shows these warnings for build optimization.

Gunjan Khanwilkar
  • 2,227
  • 2
  • 11
  • 13