Skip to content

Cannot find module '/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js' #460

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

Open
mattgodbolt opened this issue May 7, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@mattgodbolt
Copy link

mattgodbolt commented May 7, 2025

Describe the bug

In my typescript ESM module project (https://github.com/compiler-explorer/compiler-explorer) I tried to install and use this package, and it picks up @modelcontextprotocol/sdk@1.11.0. That package appears to come from git+ssh://git@github.com/modelcontextprotocol/typescript-sdk.git#621ccea...
This git package is missing the dist subdirectory.

To Reproduce

  1. Create a new project and install dependencies:
mkdir mcp-repro && cd mcp-repro
npm init -y
npm install @modelcontextprotocol/sdk@github:modelcontextprotocol/typescript-sdk tsx
  1. Create a simple TypeScript file (mcp-repro.ts):
// Simple file to test MCP SDK import
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
console.log('McpServer successfully imported:', McpServer);
  1. Run the file with tsx: npx tsx mcp-repro.ts

Expected behavior
The script should successfully import the McpServer class from the SDK and output its details.

Actual behavior

$ npx tsx mcp-repro.ts
node:internal/modules/cjs/loader:1281
  const err = new Error(`Cannot find module '${request}'`);
              ^

Error: Cannot find module '/tmp/mcp-repro/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1281:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:1269:15)
    at resolveExports (node:internal/modules/cjs/loader:638:14)
    at Function._findPath (node:internal/modules/cjs/loader:743:31)
    at node:internal/modules/cjs/loader:1230:27
    at nextResolveSimple (/tmp/mcp-repro/node_modules/tsx/dist/register-D2KMMyKp.cjs:3:942)
    at /tmp/mcp-repro/node_modules/tsx/dist/register-D2KMMyKp.cjs:2:2550
    at /tmp/mcp-repro/node_modules/tsx/dist/register-D2KMMyKp.cjs:2:1624
    at resolveTsPaths (/tmp/mcp-repro/node_modules/tsx/dist/register-D2KMMyKp.cjs:3:760)
    at /tmp/mcp-repro/node_modules/tsx/dist/register-D2KMMyKp.cjs:3:1038 {
  code: 'MODULE_NOT_FOUND',
  path: '/tmp/mcp-repro/node_modules/@modelcontextprotocol/sdk/package.json'
}

Node.js v22.13.1

Additional context

Related issues:

  1. Issue Error [ERR_PACKAGE_PATH_NOT_EXPORTED] when importing @modelcontextprotocol/sdk #427: Error [ERR_PACKAGE_PATH_NOT_EXPORTED] when importing @modelcontextprotocol/sdk #427
    - Nearly identical to our error - package can't find the specified paths
    - Problem with the exports field in package.json not correctly mapping to dist files
  2. Issue ERR_MODULE_NOT_FOUND When Importing from proxyProvider Without .js Extension #440: ERR_MODULE_NOT_FOUND When Importing from proxyProvider Without .js Extension #440
    - Similar module not found error
    - Workaround: add .js extension to imports (though this won't help in our case)
  3. Issue Module Resolution Error in ESM: Unable to Resolve @modelcontextprotocol/sdk/types.js #459: Module Resolution Error in ESM: Unable to Resolve @modelcontextprotocol/sdk/types.js #459
    - Another module resolution issue in ESM context
    - Very similar error pattern to what we're experiencing

The core issue appears to be in how the SDK is packaged and exported:

  1. The package.json has an exports field that points to:
    "exports": {
    "./": {
    "import": "./dist/esm/
    ",
    "require": "./dist/cjs/*"
    }
    }
  2. However, when installed, the dist directory is missing entirely, causing any imports
    to fail with ERR_MODULE_NOT_FOUND
  3. This is likely happening because the package is being installed directly from GitHub
    without being properly built first.
@mattgodbolt mattgodbolt added the bug Something isn't working label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant