Skip to content

Conversation

@jaffrepaul
Copy link
Contributor

Summary

Fixes CJS/ESM compatibility issues with mdx-bundler/client in Vercel serverless functions.

The mdx-bundler package uses "type": "module" but mdx-bundler/client uses CommonJS require() internally, causing runtime errors:

require() of ES Module not supported

Changes:

  • Add src/getMDXComponent.ts - local implementation ported from mdx-bundler/client
  • Update imports in page.tsx, include.tsx, platformContent.tsx
  • Fully exclude node_modules/mdx-bundler/**/* from serverless bundles
  • Refactor next.config.ts to use shared sharedExcludes array (reduces duplication)

Test plan

  • TypeScript compiles without errors
  • ESLint passes
  • Verified getMDXComponent works with mock compiled MDX code
  • Verify docs site builds and renders correctly
  • Verify serverless functions no longer have CJS/ESM errors

🤖 Generated with Claude Code

jaffrepaul and others added 2 commits January 30, 2026 17:29
The mdx-bundler package has CJS/ESM compatibility issues when loaded
in Vercel serverless functions. This adds a local implementation of
getMDXComponent that only requires React at runtime.

Changes:
- Add src/getMDXComponent.ts as local implementation
- Update imports in page.tsx, include.tsx, platformContent.tsx
- Fully exclude mdx-bundler from serverless bundles
- Refactor next.config.ts to use shared exclusion array

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
develop-docs Ready Ready Preview, Comment Jan 30, 2026 11:20pm
sentry-docs Ready Ready Preview, Comment Jan 30, 2026 11:20pm

Request Review

@jaffrepaul jaffrepaul changed the title fix: Replace mdx-bundler/client with local getMDXComponent fix(nextjs): Replace mdx-bundler/client with local getMDXComponent Jan 30, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

jaffrepaul and others added 2 commits January 30, 2026 18:09
Update ApiPage to import getMDXComponent from the local implementation
instead of mdx-bundler/client, which is excluded from serverless bundles.
This prevents module resolution errors if the serverless function is
invoked at runtime.

Also removes broken @see link from getMDXComponent.ts.

Co-Authored-By: Claude <noreply@anthropic.com>
@@ -1,8 +1,8 @@
import {Fragment, ReactElement, useMemo} from 'react';
import {bundleMDX} from 'mdx-bundler';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The ApiPage component calls bundleMDX at runtime, but mdx-bundler is excluded from the serverless bundle, which will cause a module resolution error on API pages.
Severity: CRITICAL

Suggested Fix

Since mdx-bundler is required at runtime for API pages, it should not be excluded from the serverless bundle. Remove the 'node_modules/mdx-bundler/**/*' exclusion from next.config.ts. Alternatively, pre-process the API descriptions at build time so that bundleMDX is not needed at runtime.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/components/apiPage/index.tsx#L2

Potential issue: API documentation pages are rendered dynamically at runtime. The
`ApiPage` component uses the `bundleMDX` function from the `mdx-bundler` package to
parse markdown in API parameter descriptions. However, the `next.config.ts` file has
been updated to exclude the `mdx-bundler` package from the serverless function bundle.
When a user navigates to an API page, the server will attempt to call `bundleMDX`, fail
to find the module, and throw a runtime error, causing the page request to fail.

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.

2 participants