nextjs - 💡(How to fix) Fix @next/mdx: unhandled promise rejection when plugin path fails to resolve in mdx-js-loader [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

The build process hangs without any error message, or Node.js throws an UnhandledPromiseRejection without webpack properly reporting the error. Webpack should receive the error via callback and report it clearly: Error: Cannot find module 'remark-plugin-does-not-exist' // Missing: .catch((error) => callback(error))

Root Cause

Root cause: In packages/next-mdx/mdx-js-loader.js, the Promise returned by getOptions() is missing a .catch() handler. When a plugin string path fails to resolve (e.g., module not found, ESM import failure), the rejection is never forwarded to webpack's callback, causing the build to stall.

Fix Action

Fixed

Code Example

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Enterprise
  Available memory (MB): 32488
  Available CPU cores: 16
Binaries:
  Node: 24.14.0
  npm: 11.9.0
  Yarn: N/A
  pnpm: 11.1.1
Relevant Packages:
  next: 16.3.0-canary.29 // Latest available version is detected (16.3.0-canary.29).
  eslint-config-next: N/A
  react: 19.2.6
  react-dom: 19.2.6
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/Jinoko01/mdx-catch-bug

To Reproduce

  1. Clone the reproduction repo
  2. Run npm install
  3. Run npm run build (next build --webpack)
  4. Observe the build hangs indefinitely or throws UnhandledPromiseRejection

Current vs. Expected behavior

Current: The build process hangs without any error message, or Node.js throws an UnhandledPromiseRejection without webpack properly reporting the error.

node:internal/process/promises:288 UnhandledPromiseRejection: Cannot find module 'remark-plugin-does-not-exist'

Expected: Webpack should receive the error via callback and report it clearly:

Error: Cannot find module 'remark-plugin-does-not-exist' Require stack: ...

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Enterprise
  Available memory (MB): 32488
  Available CPU cores: 16
Binaries:
  Node: 24.14.0
  npm: 11.9.0
  Yarn: N/A
  pnpm: 11.1.1
Relevant Packages:
  next: 16.3.0-canary.29 // Latest available version is detected (16.3.0-canary.29).
  eslint-config-next: N/A
  react: 19.2.6
  react-dom: 19.2.6
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Markdown (MDX), Webpack

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

Root cause: In packages/next-mdx/mdx-js-loader.js, the Promise returned by getOptions() is missing a .catch() handler. When a plugin string path fails to resolve (e.g., module not found, ESM import failure), the rejection is never forwarded to webpack's callback, causing the build to stall.

// Current code (line 61) getOptions(options, this.context).then((userProvidedMdxOptions) => { mdxLoader.call(proxy, ...args) }) // Missing: .catch((error) => callback(error))

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING