AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

@Next/Mdx: Unhandled Promise Rejection When Plugin Path Fails To Resolve In Mdx-Js-Loader

In @next/mdx, the mdx-js-loader uses getOptions() which returns a Promise. The Promise lacks a .catch(), so if a plugin path fails to resolve (e.g. missing module, ESM import failure), the rejection is unhandled. This causes webpack's build to hang without a clear error, instead of forwarding the error to webpack's callback.

highConfidence 95%Next.jsAffected V16.3.0-Canary.29

Origin Analysis

The Promise returned by getOptions() in packages/next-mdx/mdx-js-loader.js is missing a .catch() handler, so rejected promises are never passed to webpack's callback, leading to an unhandled promise rejection and build stall.
1. Clone https://github.com/Jinoko01/mdx-catch-bug 2. Run npm install 3. Run npm run build (next build --webpack) 4. Observe build hangs indefinitely or throws UnhandledPromiseRejection 'Cannot find module ...'

Fixing Code Block

Edge Case Audit

Ensure the callback error path does not conflict with mdxLoader's own callback if it also handles errors; verify the loader's callback is not called twice. Rollback: simply remove the added .catch() if unexpected double-callback or error swallowing occurs.

Ecosystem Topology