-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(nextjs): Replace mdx-bundler/client with local getMDXComponent #16232
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
base: master
Are you sure you want to change the base?
Conversation
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 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this 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.
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 <[email protected]>
| @@ -1,8 +1,8 @@ | |||
| import {Fragment, ReactElement, useMemo} from 'react'; | |||
| import {bundleMDX} from 'mdx-bundler'; | |||
There was a problem hiding this comment.
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.
Summary
Fixes CJS/ESM compatibility issues with
mdx-bundler/clientin Vercel serverless functions.The mdx-bundler package uses
"type": "module"butmdx-bundler/clientuses CommonJSrequire()internally, causing runtime errors:Changes:
src/getMDXComponent.ts- local implementation ported from mdx-bundler/clientpage.tsx,include.tsx,platformContent.tsxnode_modules/mdx-bundler/**/*from serverless bundlesnext.config.tsto use sharedsharedExcludesarray (reduces duplication)Test plan
getMDXComponentworks with mock compiled MDX code🤖 Generated with Claude Code