-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(packages): add types/typesVersions for legacy moduleResolution: node #1898
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@modelcontextprotocol/client': patch | ||
| '@modelcontextprotocol/server': patch | ||
| '@modelcontextprotocol/node': patch | ||
| '@modelcontextprotocol/express': patch | ||
| --- | ||
|
|
||
| Add top-level `types` field (and `typesVersions` on server for its subpath) so consumers on legacy `moduleResolution: "node"` can resolve type declarations. The `exports` map remains the source of truth for `nodenext`/`bundler` resolution. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,5 +63,6 @@ | |
| "typescript": "catalog:devTools", | ||
| "typescript-eslint": "catalog:devTools", | ||
| "vitest": "catalog:devTools" | ||
| } | ||
| }, | ||
| "types": "./dist/index.d.mts" | ||
|
Check failure on line 67 in packages/middleware/express/package.json
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 The sibling Extended reasoning...The stated goal of this PR is to make every published v2 package resolvable under TypeScript's legacy
"exports": {
".": {
"types": "./dist/index.d.mts",
"import": "./dist/index.mjs"
}
}Neither has a top-level Step-by-step proof:
Nothing else covers this gap. The changeset-bot lists fastify/hono only because they get a transitive bump via the Fix: add |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 The client package also exports
./validators/cf-worker(identical to server), but only server got atypesVersionsmapping here. Under legacymoduleResolution: "node",import ... from '@modelcontextprotocol/client/validators/cf-worker'will still fail with TS2307. The client package needs the sametypesVersionsblock.Extended reasoning...
What's happening
This PR's stated goal is to make the v2 packages resolvable under TypeScript's legacy
moduleResolution: "node"(Node10), which ignores theexportsmap. It does so by adding a top-leveltypesfield to each leaf package, plus a narrowtypesVersionsmap "where subpaths exist". The server package gets:However,
packages/client/package.jsonhas the exact same subpath in itsexportsmap:…yet client only received the top-level
typesfield, not thetypesVersionsmapping.Why legacy resolution can't find it without
typesVersionsUnder
moduleResolution: "node":exportsmap is ignored entirely.@modelcontextprotocol/client, TS falls back to the top-leveltypesfield — which now works thanks to this PR.@modelcontextprotocol/client/validators/cf-worker, TS consultstypesVersionsfirst; if absent, it tries to resolve the literal pathnode_modules/@modelcontextprotocol/client/validators/cf-worker(.d.ts|/index.d.ts).dist/validators/cfWorker.d.mts(different directory, camelCase filename,.d.mtsextension). Resolution fails with TS2307: Cannot find module '@modelcontextprotocol/client/validators/cf-worker'.Step-by-step proof
Given a consumer with:
@modelcontextprotocol/client/package.json, ignoresexports.typesVersionsfield is present → no remapping..../client/validators/cf-worker.d.ts,.../client/validators/cf-worker/index.d.ts, etc. → none exist (onlydist/is shipped per thefilesfield).The same import against
@modelcontextprotocol/server/validators/cf-workerdoes resolve after this PR, because server'stypesVersionsremaps it. So the PR fixes server but leaves client with the very bug it set out to address — a partial migration.Impact
Any consumer on legacy
moduleResolution: "node"who imports the client-side cf-worker validator will still hit TS2307. Since the PR description and changeset explicitly claim to cover "subpaths where they exist", this is an incomplete fix rather than an intentional omission.Fix
Add the identical block to
packages/client/package.json:The changeset text should also be updated to mention client (it currently says "and
typesVersionson server for its subpath").