Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add es import option in the package exports #1027

Closed

Conversation

robertIsaac
Copy link

@mmghv
Copy link
Collaborator

mmghv commented Jan 23, 2024

This will be resolved in v4 when we move away from the default export and rework the build system.

For now you could explicitly import jspdf-autotable/es for the ESM version.

@simonbengtsson What do you think? I suggest leaving this as-is right now so we don't introduce any breaking changes in v3.

@mmghv
Copy link
Collaborator

mmghv commented Jan 23, 2024

Note: this seems to be an issue only for dynamic imports await import(...), for static import it works just fine import autoTable from 'jspdf-autotable'.

@robertIsaac
Copy link
Author

For now you could explicitly import jspdf-autotable/es for the ESM version.

Unfortunately it throw an error
https://github.com/robertIsaac/jspdf-autotable-error-reprod
Here is example

You can read the discussion here
angular/angular-cli#26888 (comment)

@mmghv
Copy link
Collaborator

mmghv commented Jan 24, 2024

I was able to get it to work after setting module and moduleResolution TS config to nodeNext as mentioned in the thread, I also needed to add type: "module" in package.json.

But without all this, I was able to convert the dynamic import to static import and it worked fine in production, do you really need the dynamic import? this seems to be an issue with esbuild in angular and default exports for CommonJS libs transformed from ESM.

@robertIsaac
Copy link
Author

Yeah I need the dynamic import so I don't load the package (along others) unless the user started exporting, this helps a lot with the initial build size

@mmghv
Copy link
Collaborator

mmghv commented Jan 24, 2024

Have you tried the TS config solution?

@robertIsaac
Copy link
Author

Have you tried the TS config solution?

No it will probably cause even more problems but I will try it later today or tomorrow when I have time

@simonbengtsson
Copy link
Owner

Didn't know about the 'import' option. Added it now now in the v4 branch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants