Skip to content

Error [ERR_PACKAGE_PATH_NOT_EXPORTED] when importing @modelcontextprotocol/sdk #427

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
LofiSu opened this issue Apr 29, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@LofiSu
Copy link

LofiSu commented Apr 29, 2025

Title: Error [ERR_PACKAGE_PATH_NOT_EXPORTED] when importing @modelcontextprotocol/sdk

Body:

Description:

I am encountering the following error when trying to start my NestJS application using the @modelcontextprotocol/sdk package:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in E:\nestMcp\in-browser-mcp-backend\node_modules\@modelcontextprotocol\sdk\package.json
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at new NodeError (node:internal/errors:405:5)
    at exportsNotFound (node:internal/modules/esm/resolve:366:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:713:9)
    at resolveExports (node:internal/modules/cjs/loader:590:36)
    at Module._findPath (node:internal/modules/cjs/loader:664:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1126:27)
    at Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (E:\nestMcp\in-browser-mcp-backend\src\mcp\mcp.provider.ts:3:1) 
    ...

Environment:

  • Node.js version: v18.20.4
  • @modelcontextprotocol/sdk version: ^1.10.2
  • Operating System: Windows

Steps to reproduce:

  1. Install dependencies using pnpm install.
  2. Run the application with pnpm run start.
  3. The application fails to start with the above error.

Expected behavior:

The application should start without any errors.

Additional context:

It seems that the @modelcontextprotocol/sdk package does not properly define an exports field in its package.json, which causes Node.js to throw an ERR_PACKAGE_PATH_NOT_EXPORTED error when attempting to import from the package.

Could you please look into this and provide guidance or a fix?

Possible Solution:

  • Verify that the exports field is correctly set in the package.json of @modelcontextprotocol/sdk.
  • Alternatively, if you know of any workaround or patch, please let me know.

Thank you!

@LofiSu LofiSu added the bug Something isn't working label Apr 29, 2025
@edinsoncs
Copy link

the same thing happens to me

[vite] Internal server error: Failed to resolve import "@modelcontextprotocol/sdk/client/index.js" from "src/mcp/client.ts". Does the file exist?

@floherent
Copy link

Hi all, just confirming that I'm running into the same issue when trying to use the SDK in an ESM-based Node.js project using version 1.11.0.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server/mcp.js' is not defined by "exports" in the package.json

When I run the project locally with:

node /absolute/path/to/weather/build/index.js # node 22.10

it works fine. However, when I try to load the same project into the Claude Desktop app (Claude for Mac – version 0.9.3), it crashes, and the log shows the error above.

I'm following the example listed here: https://modelcontextprotocol.io/quickstart/server#node

Note: I did notice the conditional exports pointing to ./server/mcp.js in the package.json:

"exports": {
    "./*": {
      "import": "./dist/esm/*",
      "require": "./dist/cjs/*"
    }
 }

I will try to run some more debugging and find a fix for this because I don't feel like using CommonJS.

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

3 participants