fix: serve correct CJS type declarations from package.json exports - #21
Merged
Conversation
Every exports entry pointed `types` at the ESM `.d.mts` even under the `require` condition, so TS `node16`/`nodenext` CJS consumers resolved ESM declarations for a CJS `require` — the classic attw "incorrect types for require" failure. The build already emits `.d.cts` for the index and all 7 subpaths; they were just unreachable. Nest `types` under `import`/`require` per subpath (`.d.mts` for import, `.d.cts` for require), point the top-level `types` at `.d.cts` to match `main` (CJS), add `typesVersions` so legacy node10 resolves subpath types, and expose `./package.json`. Verified with @arethetypeswrong/cli: "No problems found" across node10, node16 (CJS + ESM), and bundler. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
🎉 This PR is included in version 2.0.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Audit medium M4.
Problem
Every
exportsentry (and the top-leveltypes) pointed at the ESM.d.mtsdeclaration — including under the"require"condition. So a TSnode16/nodenextconsumer doingrequire("@klinking/colander")(or a subpath) resolved ESM type declarations for a CJS import — the classic attw "incorrect types for require" failure. The build already emits.d.ctsfor the index and all 7 format subpaths; they were simply unreachable.Fix
typesunderimport/requireper subpath:.d.mtsforimport,.d.ctsforrequire, withdefaultfor the JS.typesat.d.ctsto matchmain(which is the CJSindex.cjs).typesVersionsmapping each subpath to its.d.ctsso legacymoduleResolution: node(node10) — which can't readexportssubpaths — also resolves subpath types. (This axis was already failing before; the flat map never supported it either.)./package.json.Verification
@arethetypeswrong/cli --pack→ "No problems found 🌟", all green across node10, node16 (from CJS), node16 (from ESM), and bundler (was 💀 for node16-from-CJS on every entry, and 💀 for node10 subpaths).vp run ready: lint+typecheck 0/0, all suites green.🤖 Generated with Claude Code