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

Feature request: support for native Ecma script modules #192

Open
Havunen opened this issue Oct 4, 2023 · 4 comments
Open

Feature request: support for native Ecma script modules #192

Havunen opened this issue Oct 4, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@Havunen
Copy link

Havunen commented Oct 4, 2023

I'm requesting this module to add support for native ESM modules so it can be loaded in environments where common js is not supported. For example jest native ESM mode.

add "type": "module" to package.json and "exports" entry point

@Aymkdn
Copy link
Owner

Aymkdn commented Oct 4, 2023

I'm afraid that it will break the module import for many people (including me)… depending on the version of Node and how old your projects are.

I'd have to run some tests, but it's not on my priority list right now, so don't hold your breath!

@Aymkdn Aymkdn added the enhancement New feature or request label Oct 4, 2023
@Havunen
Copy link
Author

Havunen commented Oct 4, 2023

What about bumping major version to v3 to indicate the braking change and supporting both v2 and v3 temporarily?

@Aymkdn
Copy link
Owner

Aymkdn commented Oct 4, 2023

What about bumping major version to v3 to indicate the braking change and supporting both v2 and v3 temporarily?

Yes, but it means more work for me because I'll have to maintain two branches. I'll think about it.

@SatishB15
Copy link

Solution for using html-to-pdfmake in module-based environments (e.g., Angular 18, Jest ESM)

I encountered the same issue while using html-to-pdfmake in Angular 18 due to its CommonJS implementation not being compatible with native ES Modules. Instead of the standard:

import * as htmlToPdfMake from 'html-to-pdfmake';

I used the following alternative syntax:

import _ from 'html-to-pdfmake';

This syntax resolved the issue and allowed the library to function seamlessly in an ESM environment.

Why it Works
• This syntax ensures compatibility with CommonJS modules in environments expecting ES Module exports.
• The underscore _ correctly handles the default export from the CommonJS module.

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

No branches or pull requests

3 participants