CommonJS export paths broken - missing index.js file in dist/cjs
Opened this issue · 3 comments
Describe the bug
The CommonJS exports in @modelcontextprotocol/sdk package are broken due to missing dist/cjs/index.js file. The package.json exports configuration points to non-existent files, causing MODULE_NOT_FOUND errors when importing from the main package entry point in CommonJS/Node.js environments.
To Reproduce
Steps to reproduce the behavior:
- Create a Node.js project with CommonJS module resolution (or TypeScript compiling to CommonJS)
- Install
@modelcontextprotocol/sdk@^1.17.3 - Try to import from the main export:
import { McpError } from "@modelcontextprotocol/sdk" - Run the application with Node.js
- Observe the MODULE_NOT_FOUND error
Minimal reproduction:
// test.js
const { McpError } = require('@modelcontextprotocol/sdk');
console.log(McpError);node test.js
# Error: Cannot find module '/path/to/node_modules/@modelcontextprotocol/sdk/dist/cjs/index.js'Expected behavior
The main package import should work without errors:
import { McpError } from "@modelcontextprotocol/sdk";
// Should successfully import McpError classLogs
Error: Cannot find module '/Users/adam/src/maxcare-ai/monorepo/node_modules/@modelcontextprotocol/sdk/dist/cjs/index.js'
at createEsmNotFoundErr (node:internal/modules/cjs/loader:1447:15)
at finalizeEsmResolution (node:internal/modules/cjs/loader:1436:9)
at resolveExports (node:internal/modules/cjs/loader:671:14)
at Module._findPath (node:internal/modules/cjs/loader:738:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1396:27)
at defaultResolveImpl (node:internal/modules/cjs/loader:1051:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1056:22)
at Module._load (node:internal/modules/cjs/loader:1219:37)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:238:24) {
code: 'MODULE_NOT_FOUND',
path: '/Users/adam/src/maxcare-ai/monorepo/node_modules/@modelcontextprotocol/sdk'
}
Additional context
- Package version: 1.17.3 (also affects 1.17.4)
- Node.js version: 24.7.0
- Environment: TypeScript project compiled to CommonJS
Root cause analysis:
The package.json exports configuration references:
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js" // ❌ This file doesn't exist
}
}Actual file structure:
dist/cjs/
├── types.js ✅ (contains McpError)
├── server/index.js ✅
├── client/index.js ✅
├── cli.js ✅
└── index.js ❌ missing
Current workaround:
Using the full path import works: import { McpError } from "@modelcontextprotocol/sdk/types.js"
Suggested fix:
Either create the missing dist/cjs/index.js file that re-exports the main classes/functions, or update the exports configuration to point to existing files like types.js for the main export.
#870 will solve this. But in there, the main export still needs to be removed or a breaking change needs to be decided on as per comment.
@KKonstantinov is this one still worked by you?
It was tagged as "ready for work" 2 days ago and it seems like you have a pr for that already in motion
@KKonstantinov is this one still worked by you?
It was tagged as "ready for work" 2 days ago and it seems like you have a pr for that already in motion
Hi, yes there's a PR for that (#870) which is scheduled to be merged in the next major version of the SDK (see the v2 milestone here on Github)