(fix): respect tsconfig esModuleInterop flag #327
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.
the previous assumption that ESM users will always import the ESM
build doesn't actually hold up in practice due to various limitations
in Node and testing and the prevalence of transpiling in general
the CJS build, and this option would break compatibility
without esModule set, CJS users would be unable to use the default
export of any library built with tsdx
breaking changes in libraries that use default exports and try to
adopt tsdx
so, instead of always setting rollup's esModule to false and
potentially causing unintended consequences, respect the user's
esModuleInterop config as set in their tsconfig, but default to
false
Fixes #165 according to my suggestion in #165 (comment) . Mine and other folk's comments in that issue give more details about the compatibility and adoption issues that drive this PR. Ultimately, I believe this is a bugfix as the current behavior causes unintended consequences and because default exports are already output, just not with
__esModule
in CJS builds.Have tested this successfully locally. All it does is, if
esModuleInterop
is set totrue
intsconfig.json
, will add a line of code to the CJS output as such:As I mentioned in #165 (comment), everything else is the same as before, as ESM builds already output
export default
and CJS builds already outputexports.default
.__esModule
is just a hint for transpilers to use.default
when transpiling default imports to CJS.