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

Exports types for resolution in ESM Modules #112

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

jmlow
Copy link
Contributor

@jmlow jmlow commented Nov 27, 2024

While working with the buttercms NPM package in v2.3.0, I kept receiving the following Typescript error:

"Could not find a declaration file for module 'buttercms'. '/home/justi/projects/nv-web-platform/node_modules/buttercms/dist/butter.esm.js' implicitly has an 'any' type.

There are types at '/home/justi/projects/nv-web-platform/node_modules/buttercms/lib/butter.d.ts', but this result could not be resolved when respecting package.json "exports". The 'buttercms' library may need to update its package.json or typings."

From my research, I found an example at https://antfu.me/posts/publish-esm-and-cjs#tsup

It looks like when you split the exports between cjs and esm, you also need to export the types in package.json for the typings to apply to both exports.

I tested this by patching the package.json in my local node_modules and it fixes the issue.

Since I already did the research and it's a one-line fix, I figured I'd just submit a PR instead of an issue. I hope that's alright!

@ViolanteCodes
Copy link
Contributor

@jmlow Thank you! An issue with a fix is my favorite kind of issue ticket

@marcinpece-apptension @courcelan could you take a look? FYI we will need to prefix commit method with fix: before merging

Copy link
Contributor

@courcelan courcelan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. As I take it through research, this exposes the existing typescript types and doesn't re-export them as our webpack build process does not do so. should be good to go.

@courcelan courcelan merged commit 5fee260 into ButterCMS:master Dec 5, 2024
1 check passed
courcelan added a commit that referenced this pull request Dec 6, 2024
Merge pull request #112 from jmlow/esm-typings
@ViolanteCodes
Copy link
Contributor

@jmlow thank you, merged and new version released

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

Successfully merging this pull request may close these issues.

3 participants