fix: support modern esm and types resolution #48
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.
Currently, the package won't run with vite/rollup which is arguably one of the most (if not the most) popular bundler setup.
First, it would use a CJS build instead of ESM build even in pure ESM (
"type": "module"
) projects. This is because the ESM build is not published in a standard-compliant way.Then, with CJS build, it will not import sub-deps properly:
Then, under some circumstances the types won't load with modern Typescript setup ("moduleResolution" set to "Node16" or "Bundler") with this error: ...There are types at '/......./types/index.d.ts', but this result could not be resolved when respecting package.json "exports".ts(7016)
All and all, the project's
package.json
is missing theexports
section which modern packages should have. The PR adds one.Also, the top-level
module
property should be removed frompackage.json
as there is no such field officially. It could have been supported privately by some bundlers but now everything supportsexports
. I keptmodule
in this PR as you may have been relying on it somehow—but please consider removing it.