fix: avoid star exporting react components #140
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #104.
The CommonJS build is currently broken due to a duplicate export with the name
render
. Any project which currently imports the CommonJS build will get anUncaught TypeError: Cannot redefine property: render
error.The reason for this is because all of the sub packages are star exported from the main entrypoint, which results in multiple exports with the name
render
.You can confirm this problem by creating the following simple CommonJS file, and seeing the error.
When the entrypoint compiles down to CommonJS, it ends up like this. Each of these Object.keys blocks is looping over all the exports from the sub package, and attaching them to exports using Object.defineProperty.
You cannot use Object.defineProperty to redefine an existing property. So the first block defines a render property on exports, and then subsequent packages try to set the same property, causing the error.
I note that in the documentation, all the React components are imported via their name anyway, so these star exports are not needed, apart from
@uiw/color-convert
which contains utility functions.By removing the star exports, we no longer get
render
directly exported multiple times in the CommonJS file, and the problem is fixed.