ERR_REQUIRE_ESM importing SSEClientTransport from @modelcontextprotocol/sdk in a CJS project
In a CommonJS project on Node.js v22.6.0, importing
SSEClientTransportfrom@modelcontextprotocol/sdk/client/sse.jsfails withERR_REQUIRE_ESMbecause the SDK's CJS build requires the ESM packagepkce-challenge. How can I use the SSE client transport from a CommonJS project, and is this fixed in a later SDK version?Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/203
5 answers
Status: closed (completed). No maintainer replied in the thread; one user reported that upgrading to
@modelcontextprotocol/sdkv1.9.0 resolved the error, and another user confirmed a dynamic-import workaround.Root cause: importing
SSEClientTransportpulls in the SDK's CommonJS build (dist/cjs/client/auth.js), which doesrequire()ofpkce-challenge. That package's nearestpackage.jsondeclares"type": "module", so Node.js rejects therequire()call withERR_REQUIRE_ESMon Node.js v22.6.0. On Node.js 23 the same import path produced a relatedERR_REQUIRE_ASYNC_MODULEerror. Server-side imports from the SDK worked fine; the failure is specific to the client/auth code path.Workaround reported in the thread: replace the top-level import with a dynamic import inside an async function:
typescriptconst SSEClientTransport = (await import('@modelcontextprotocol/sdk/client/sse.js')).SSEClientTransport;Also reported: upgrading to
@modelcontextprotocol/sdkv1.9.0 made the problem go away for one user.Did this work for you?What @wictorwilen tried on GitHub (Worked)
Replaced the top-level import with a dynamic import inside an async function:
const SSEClientTransport = (await import('@modelcontextprotocol/sdk/client/sse.js')).SSEClientTransport;.Did this work for you?What @henrytsuicsa tried on GitHub (Worked)
Upgraded to
@modelcontextprotocol/sdkv1.9.0; the user reported "seems problem solved".Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Used a top-level named import
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";in a CJS project on Node.js v22.6.0, which threwERR_REQUIRE_ESMbecauserequire()hit the ESM filepkce-challenge/dist/index.node.js.Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/203 (opens external site)
Did this work for you?What @anandrewfiserv tried on GitHub (Didn't work)
On Node.js 23, the same import path produced a different error,
ERR_REQUIRE_ASYNC_MODULE, instead ofERR_REQUIRE_ESM.Did this work for you?
Related questions
- MCP TypeScript SDK StreamableHttp without sticky sessions in multi-replica deployments?
- MCP stdio server: SyntaxError Unexpected token in deserializeMessage when using console.log
- MCP typescript-sdk: tool inputSchema/outputSchema reject JSON Schema type 'array'?
- Use Zod union/intersection as MCP tool paramsSchema in typescript-sdk?
- MCP Inspector: "Invalid transport type: undefined" when connecting to an SSE server