nextjs - ✅(Solved) Fix Webpack cache warning from `@next/mdx` during `next build` with MDX in App Router [1 pull requests, 1 participants]

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…
GitHub stats
vercel/next.js#89753Fetched 2026-04-08 02:02:24
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
cross-referenced ×1issue_type_added ×1labeled ×1

Root Cause

  • The warning appears even though the build completes successfully and all pages render as expected.
  • The warning comes from the official @next/mdx integration (mdx-js-loader.js), not from custom loaders or custom webpack configuration in the app.
  • It seems related to the dynamic import(process.platform === 'win32' ? pathToFileURL(path) : path) used inside the loader, which webpack’s cache analyzer cannot fully understand for dependency tracking.
  • The concern is:
    • Noise in production builds caused by a warning coming from official Next.js MDX tooling, and
    • The note that “build dependencies behind this expression are ignored and might cause incorrect cache invalidation,” which suggests that cache correctness may rely on implementation details in this loader.
  • It would be helpful to know whether this warning can be safely ignored, or if @next/mdx can be adjusted so that webpack can analyze its dependencies without emitting this warning.

Fix Action

Fixed

PR fix notes

PR #90026: fix(next-mdx): avoid webpack cache warning for dynamic plugin imports

Description (problem / solution / changelog)

What?

Fix @next/mdx loader dynamic plugin import handling to avoid webpack cache dependency-analysis warnings during next build --webpack.

  • Normalize runtime import target to a string importPath
  • Keep Windows compatibility via pathToFileURL(path).href
  • Use import(/* webpackIgnore: true */ importPath) for runtime-only Node import

Why?

When using @next/mdx, webpack may warn about parsing build dependencies behind a dynamic import(...) expression in mdx-js-loader.js.

This import is intentionally runtime-only in Node loader execution, and static dependency analysis here is not useful but can produce noisy warnings and confusing cache-invalidation messages.

Fixes #89753

How?

Changed packages/next-mdx/mdx-js-loader.js:

  • Before:
    • await import(process.platform === 'win32' ? pathToFileURL(path) : path)
  • After:
    • compute importPath first
    • await import(/* webpackIgnore: true */ importPath)

This preserves behavior while avoiding webpack build-dependency analysis on this runtime import path.

Validation

  • pnpm build (in next.js) passed
  • pnpm test-dev-webpack test/e2e/app-dir/mdx/mdx.test.ts passed (27/27)
  • pnpm test-dev-webpack test/e2e/app-dir/mdx-no-mdx-components/mdx.test.ts passed (4/4)

Checklist

  • Related issue linked (Fixes #89753)
  • Tests added
  • Change is minimal and scoped to @next/mdx loader behavior

Changed files

  • packages/next-mdx/mdx-js-loader.js (modified, +5/-4)

Code Example

git clone https://github.com/pieterjanscheir/my-minimal-nextjs-issue-reproduction.git
   cd my-minimal-nextjs-issue-reproduction
   pnpm install

---

pnpm build
   # or
   pnpm next build --webpack

---

<w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /.../node_modules/@next/mdx/mdx-js-loader.js for build dependencies failed at 'import(process.platform === 'win32' ? pathToFileURL(path) : path)'.
   <w> Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.

---

[webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /.../node_modules/@next/mdx/mdx-js-loader.js for build dependencies failed at 'import(process.platform === 'win32' ? pathToFileURL(path) : path)'.
  Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.

---

Output of `npx --no-install next info` in the project:


Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:03:25 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 25.2.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.28.2
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  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/pieterjanscheir/my-minimal-nextjs-issue-reproduction

To Reproduce

  1. Clone the reproduction repository:

    git clone https://github.com/pieterjanscheir/my-minimal-nextjs-issue-reproduction.git
    cd my-minimal-nextjs-issue-reproduction
    pnpm install
  2. Ensure the project has MDX configured via @next/mdx (as in the reproduction), and at least one MDX page in the App Router (for example, mirroring your real setup with app/berichten/adreswijziging/page.mdx).

  3. Run a production build:

    pnpm build
    # or
    pnpm next build --webpack
  4. Observe the build output. The build succeeds, but the following warning appears:

    <w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /.../node_modules/@next/mdx/mdx-js-loader.js for build dependencies failed at 'import(process.platform === 'win32' ? pathToFileURL(path) : path)'.
    <w> Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.

Current vs. Expected behavior

Current behavior

  • next build completes successfully, but always prints this webpack cache warning originating from @next/mdx:

    [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /.../node_modules/@next/mdx/mdx-js-loader.js for build dependencies failed at 'import(process.platform === 'win32' ? pathToFileURL(path) : path)'.
    Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.
  • This suggests that webpack cannot statically analyze the dynamic import(...) in mdx-js-loader.js and therefore might not track all dependencies for its filesystem cache.

Expected behavior

  • next build should either:
    • Not emit this warning at all for the official @next/mdx loader, or
    • Handle this case internally such that cache dependencies are correctly tracked without a warning.
  • From a user perspective, using the officially supported MDX integration in a standard App Router project should not produce persistent webpack cache warnings in a clean production build.

Provide environment information

Output of `npx --no-install next info` in the project:


Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:03:25 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 25.2.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.28.2
Relevant Packages:
  next: 16.1.6 // Latest available version is detected (16.1.6).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
Next.js Config:
  output: N/A

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

Webpack

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

next build (local)

Additional context

  • The warning appears even though the build completes successfully and all pages render as expected.
  • The warning comes from the official @next/mdx integration (mdx-js-loader.js), not from custom loaders or custom webpack configuration in the app.
  • It seems related to the dynamic import(process.platform === 'win32' ? pathToFileURL(path) : path) used inside the loader, which webpack’s cache analyzer cannot fully understand for dependency tracking.
  • The concern is:
    • Noise in production builds caused by a warning coming from official Next.js MDX tooling, and
    • The note that “build dependencies behind this expression are ignored and might cause incorrect cache invalidation,” which suggests that cache correctness may rely on implementation details in this loader.
  • It would be helpful to know whether this warning can be safely ignored, or if @next/mdx can be adjusted so that webpack can analyze its dependencies without emitting this warning.

extent analysis

TL;DR

The warning from @next/mdx during next build can potentially be addressed by updating @next/mdx or adjusting webpack configuration to handle dynamic imports.

Guidance

  1. Verify the warning's impact: Confirm if the warning affects the build's correctness or performance, despite the build succeeding.
  2. Check for updates: Ensure @next/mdx and related dependencies are up-to-date, as newer versions might address this issue.
  3. Adjust webpack configuration: Consider configuring webpack to ignore this specific warning or handle dynamic imports differently, potentially by using ignoreWarnings option in next.config.js.
  4. Monitor cache behavior: Observe the build's cache behavior to determine if the warning leads to incorrect cache invalidation.

Example

No specific code example is provided due to the lack of direct code context, but adjusting next.config.js might involve something like:

module.exports = {
  //... other configurations
  webpack: (config) => {
    // Potential adjustment to ignore warnings
    config.ignoreWarnings = [/warning from @next\/mdx/];
    return config;
  },
}

However, this is speculative without direct code context.

Notes

The provided information does not specify a clear fix but suggests that the issue might be related to how webpack handles dynamic imports in @next/mdx. The warning's impact on the build's correctness and performance needs further investigation.

Recommendation

Apply a workaround by potentially adjusting webpack configuration to handle the dynamic import warning, as updating to a fixed version of @next/mdx is not explicitly mentioned as an option in the provided context.

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