fix: ESM default import This expression is not callable
#241
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.
This ought to fix #228
ESM seems incompatible in CommonJS PJs with default export (see microsoft/TypeScript#52086).
I think there are two solutions to make TypeScript types compatible with both CommonJS and ESM.
reference: https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing
Case
1
, I would make a copy of the currentindex.d.ts
, rename the file toindex.d.mts
, and change package.json as follows.However, I think this is redundant and low-maintainability because we have to manage two type definitions, so I tried to modify it in the second way(Case
2
).Explanation of this modification
export =
, both CommonJS and ESM are supported.I do not expect any impact on existing CommonJS implementations of TypeScript developers. Originally, when using
export default
, as described in Default Exports, theesModuleInterop
option must be used, and testing has confirmed that it can be compiled with this setting.Also, testing confirms that the project can be compiled with the project in the ESM configuration.
For this change, I refer to the following