Skip to content

fix(express): add CJS exports to resolve ERR_PACKAGE_PATH_NOT_EXPORTED#1911

Open
langverse2023 wants to merge 1 commit intomodelcontextprotocol:mainfrom
langverse2023:fix/express-package-exports
Open

fix(express): add CJS exports to resolve ERR_PACKAGE_PATH_NOT_EXPORTED#1911
langverse2023 wants to merge 1 commit intomodelcontextprotocol:mainfrom
langverse2023:fix/express-package-exports

Conversation

@langverse2023
Copy link
Copy Markdown

Summary

Fixes #1858

The @modelcontextprotocol/express package only defines ESM (.mjs) entries in its exports field, which causes ERR_PACKAGE_PATH_NOT_EXPORTED for consumers using CommonJS (require()). This is a common scenario for TypeScript projects initialized with default tsconfig.json settings (e.g. module: "commonjs").

Changes

  • tsdown.config.ts: Add 'cjs' to the format array so tsdown generates both .mjs and .cjs output files
  • package.json: Add require conditions to the exports field for both the main entry and type definitions

Before

"exports": {
    ".": {
        "types": "./dist/index.d.mts",
        "import": "./dist/index.mjs"
    }
}

After

"exports": {
    ".": {
        "types": {
            "import": "./dist/index.d.mts",
            "require": "./dist/index.d.cts"
        },
        "import": "./dist/index.mjs",
        "require": "./dist/index.cjs"
    }
}

Test plan

  • pnpm --filter @modelcontextprotocol/express build succeeds, generating both ESM and CJS output
  • pnpm --filter @modelcontextprotocol/express test passes (17/17 tests)
  • Verify a CJS consumer project can require('@modelcontextprotocol/express') without errors

The @modelcontextprotocol/express package only exported ESM (.mjs) format,
causing ERR_PACKAGE_PATH_NOT_EXPORTED for consumers using CommonJS/require().

Add CJS output format to tsdown config and corresponding require entries
in the package.json exports field, so both ESM and CJS consumers can
resolve the package correctly.

Fixes modelcontextprotocol#1858
@langverse2023 langverse2023 requested a review from a team as a code owner April 16, 2026 03:06
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 16, 2026

⚠️ No Changeset found

Latest commit: e683ec1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 16, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1911

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1911

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1911

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1911

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1911

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1911

commit: e683ec1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERR_PACKAGE_PATH_NOT_EXPORTED with @modelcontextprotocol/express

1 participant