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
Fix type resolution when using modern TypeScript module resolution #373
Conversation
🦋 Changeset detectedLatest commit: c22978b The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR 💥 An error occurred when fetching the changed packages and changesets in this PR
|
74f99df
to
4013820
Compare
Thanks a lot for this PR. I'd like to better understand this situation. Can you point me to some reading resources that explain the requirement to have both |
To be honest, I don't have a complete grasp of all the nuance involved here, but I'll try to corroborate my experience with Node + TypeScript documentation when I have a chance. What I do know is that setting TypeScript's I think what's happening is that when I was using the old I think the ideal solution would be to add "official" CommonJS support to all packages. I might be able to help with this if you're interested in supporting it. Short of that, this change at least makes using the new resolution mode possible. |
I just serendipitously came across this by way of a dependency upgrade:
I haven't had a chance to go through it more closely, but in skimming the conversation, it looks like a very similar issue. Perhaps they do a better job of explaining things? |
Thanks a lot for your thoughts and explanations. I'm wondering whether instead of adding the ./source-files/schema": "./dist/source-files/schema/index.js", Regarding CJS support in Contentlayer: I agree in principle that ideally every package (incl. Contentlayer) is available both as CJS and ESM module. However, given that Contentlayer is using a fair amount of ESM-specific code (e.g. |
Heh, sorry, I think I kinda missed your point here in asking about the both part. Most of that was me explaining why we need I'll update the pull request, thank you! |
4013820
to
9b8b622
Compare
9b8b622
to
c22978b
Compare
Sorry for the delay. I've published a prerelease |
This should be addressed with the |
I'm gradually working towards ECMAScript modules in our design system monorepo. One of the first steps to enabling this is switching to
moduleResolution: nodenext
ormoduleResolution: node16
in our TypeScript configuration.I've run into a couple snags related to Contentlayer because it only ships ESM, but the only true blocker I've come across so far is that the types don't resolve properly in the generated code. Specifying
default
conditions in theexports
field fixes this without having to make any source changes.Before
After