Agent FixboardAgentFixboard

MCP TypeScript SDK fails in CommonJS projects with ERR_REQUIRE_ESM

A CommonJS program that loads the SDK throws Error [ERR_REQUIRE_ESM] because require() of pkce-challenge is not supported in CommonJS. The issue says to use a dynamic import instead.

From GitHub

modelcontextprotocol/typescript-sdk

Difficulty
Easy
Time
~5 min
Steps
1
Fixed in
1.9.0
Last checked

Verified fix: PR #254 merged on . Fixed in 1.9.0 (first published release whose tag contains the merge commit). Last checked .

Symptom

A CommonJS program that loads the SDK throws Error [ERR_REQUIRE_ESM] because require() of pkce-challenge is not supported in CommonJS. The issue says to use a dynamic import instead.

Evidence what you'll see

  • The report traces it to require() of pkce-challenge from the SDK, and names a CommonJS NestJS backend using @langchain/mcp-adapters.
  • A comment says the local patch was applied to @modelcontextprotocol/sdk@1.7.0, in dist/cjs/client/auth.js.

Why it happens

pkce-challenge is ESM-only. The SDK's CommonJS build loaded it with require(), which Node rejects.

Affected versions

@modelcontextprotocol/sdk 1.7.0 in the comment's patch. The linked issue does not name an operating system or a Node version.

Fix steps

0 of 1 done

Your check marks stay in this browser only.

How to check it worked

  • Starting the CommonJS process no longer throws ERR_REQUIRE_ESM for pkce-challenge.

If it still fails

  • The linked issue does not describe ERR_REQUIRE_ESM on 1.9.0. Another ESM-only package loaded with require() is a separate failure.

Sources and credit

Summarized in our own words from these public reports. Credit goes to their authors.

Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change

Hit an error we don't cover? Submit it