gitbrent / PptxGenJS

Create PowerPoint presentations with a powerful, concise JavaScript API.
https://gitbrent.github.io/PptxGenJS/
MIT License
2.84k stars 625 forks source link

[BUG] importing pptxgen.es.js in angular warns about commonjs dependency #1280

Open jeroentvb opened 1 year ago

jeroentvb commented 1 year ago

Issue Category

Product Versions

Description

When import PptxGenJS from 'pptxgenjs'; the angular compiler warns about pptxgenjs being a commonjs module, which is valid. But when import PptxGenJS from 'pptxgenjs/dist/pptxgen.es.js'; typescript complains about not being able to find a type declaration file. When ignoring that with a @ts-ignore, the app compiles, but angular still warns about pptxgenjs being a commonjs module.

The warning is as follows:

Warning: /home/projects/node-gmxzct/src/app/app.component.ts depends on 'pptxgenjs'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

I was able to 'fix' this by modifying the package.json of pptxgenjs to include the following, but this is not desired, as this is removing the entrypoint for the commonjs bundle:

"type": "module",
"main": "dist/pptxgen.es.js",

Another 'fix' is to add pptxgenjs to the allowedCommonJsDependencies in angular.json, but this only supresses the warning.

Desired Behavior

Importing the esm bundle should work properly and the angular compiler should show no warning about pptxgenjs being a commonjs module.

Observed Behavior

Warning: /home/projects/node-gmxzct/src/app/app.component.ts depends on 'pptxgenjs'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Steps to Reproduce

See terminal in this stackblitz: https://stackblitz.com/edit/node-gmxzct?file=src%2Fapp%2Fapp.component.ts
Also try to import the esm bundle and see the same warning being shown in the terminal (app restart required. Use yarn start).