jsPDF-AutoTable icon indicating copy to clipboard operation
jsPDF-AutoTable copied to clipboard

Fix ESM module detection configuration

Open tiberiuzuld opened this issue 5 months ago • 3 comments

Hello,

I made changes to package.json to make it compatible with Angular 17 and the new esbuild/vite bundler that the angular-cli is using. I tried multiple configurations, but this last one is what also jsPDF is using and is working well with ESM modules.

https://github.com/parallax/jsPDF/blob/master/package.json

tiberiuzuld avatar Jan 23 '24 15:01 tiberiuzuld

Doesn't it work with import autoTable from 'jspdf-autotable' ? it works fine with me.

mmghv avatar Jan 23 '24 20:01 mmghv

It works when I use Ng serve but as soon as I make the production build it is no longer working. I saw some relevant comments on this issue that the other PR was also mentioned:

https://github.com/angular/angular-cli/issues/26888

From my debugging the esbuild just imports the cjs file and not the mjs one, and when it makes the final bundle, at runtime I just get an error with not a function for autotable.

I didn't use dynamic import and didn't test import from jspdf-autotable/es, but I saw in the issue above those are not working.

tiberiuzuld avatar Jan 23 '24 21:01 tiberiuzuld

I tested it myself, it works fine with static imports, what problem are you having with static import in production?

mmghv avatar Jan 24 '24 06:01 mmghv

Added a "module" field now in the new v4 branch, but kept the other things as is. Although it is non standard and should not be needed it seems that most other libraries are doing this. Also tried creating a new angular project with v4 branch which worked great.

simonbengtsson avatar Feb 02 '24 23:02 simonbengtsson