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

Correct CJS bundling #374

Open
1 task
levchak0910 opened this issue Feb 24, 2024 · 1 comment
Open
1 task

Correct CJS bundling #374

levchak0910 opened this issue Feb 24, 2024 · 1 comment

Comments

@levchak0910
Copy link

Describe the feature

Default exports are not correctly exported from CJS files

When creating a package using unbuild CJS exports cause Masquerading as ESM error (example from my lib)

Several libraries need to run a post-build script to change the source of .cjs files

Affected libs:

other can be found too: https://github.com/search?q=patchCjs&type=code

Is it possible to fix this behavior within the library?

Huge thanks to @userquin for helping to figure it out


And thanks for awesome tool )

Additional information

  • Would you be willing to help implement this feature?
@userquin
Copy link
Contributor

Masquerading as ESM error should be fixed in the package exports in the target library, the problem is about dual CJS/ESM package exports with default exports, the generated cjs module should use exports.default instead module.exports for the default export.

When using default exports, a consumer using module resolution node16 cjs or node will need an extra .default: https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/MissingExportEquals.md

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

No branches or pull requests

2 participants