nextjs - ✅(Solved) Fix Sourcemaps broken for next/dist files in Yarn PnP mode (webpack) [1 pull requests, 1 comments, 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#90129Fetched 2026-04-08 00:20:45
View on GitHub
Comments
1
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×2cross-referenced ×1issue_type_added ×1

Fix Action

Fixed

PR fix notes

PR #90138: fix(webpack): enable PnP sourcemap support in next-swc-loader pitch

Description (problem / solution / changelog)

fixes: #90129

What?

Enable pitch in next-swc-loader for Yarn PnP so sourcemap chaining works for Next.js internal files. (These files are matched by babelIncludeRegexes and transformed via pitch — see https://github.com/vercel/next.js/blob/24c6e3e4de2e729c7e71d38173466cf9cf3d5399/packages/next/src/build/webpack-config.ts#L121)

Why?

In PnP mode, pitch was skipped (!process.versions.pnp), so it fell through to swcLoader. But Webpack can't resolve .map files from zip archives, so inputSourceMap was always undefined — DevTools showed .js instead of .ts sources.

How?

  • Bypass EXCLUDED_PATHS check in PnP — PnP paths always contain __virtual__/.zip that would block pitch.
  • In PnP, read the file and its .map via Node.js fs, then pass both to loaderTransform. Yarn PnP monkey-patches fs to read from zip archives, so this just works without special handling.
  • Use resourcePath + '.map' directly instead of parsing from source. Next.js dist/ always generates .js.map alongside .js, so there's no need to regex-parse the comment.
  • This is done in pitch (not in swcLoader/loaderTransform) because files matching babelIncludeRegexes should go through pitch like they do in non-PnP mode.

Changed files

  • packages/next/src/build/webpack/loaders/next-swc-loader.ts (modified, +16/-3)

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:53:15 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 24.6.0
  npm: 11.5.1
  Yarn: 4.12.0
  pnpm: N/A
Relevant Packages:
  next: 16.1.6
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  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/WooWan/yarn-pnp-sourcemap-repro/tree/main

To Reproduce

  1. Start the application in development (yarn dev)
  2. Open Chrome DevTools → Sources tab
  3. Look for next/dist/client/components/app-router.js
  4. Instead of seeing original .ts source files, the bundled .js files are shown

Current vs. Expected behavior

Current: In Yarn PnP mode, DevTools shows .js files instead of original .ts sources for Next.js internal runti +me files (next/dist/client/, next/dist/shared/lib/, next/dist/pages/). inputSourceMap is not passed to the SWC + loader, so source map chaining is broken.

Expected: DevTools should show .ts source files, same as non-PnP mode.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.3.0: Wed Jan 28 20:53:15 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 24.6.0
  npm: 11.5.1
  Yarn: 4.12.0
  pnpm: N/A
Relevant Packages:
  next: 16.1.6
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A

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

Webpack, SWC

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

next dev (local), next build (local)

Additional context

This issue originated from https://github.com/vercel/next.js/pull/33236.

extent analysis

Fix Plan

Enable Source Map Chaining in Yarn PnP Mode

To fix the issue, we need to enable source map chaining in Yarn PnP mode. This can be achieved by passing the inputSourceMap option to the SWC loader.

Step-by-Step Solution

  1. Update next.config.js:
module.exports = {
  // ... other configurations ...
  experimental: {
    pnpSourceMap: true,
  },
};
  1. Update webpack.config.js (if you have a custom Webpack configuration):
module.exports = {
  // ... other configurations ...
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: [
          {
            loader: 'swc-loader',
            options: {
              inputSourceMap: true,
            },
          },
        ],
      },
    ],
  },
};
  1. Restart the application by running yarn dev again.

Verification

To verify that the fix worked, follow these steps:

  1. Open Chrome DevTools → Sources tab.
  2. Look for next/dist/client/components/app-router.js.
  3. Check if the original .ts source files are shown instead of the bundled .js files.

If the issue persists, ensure that the experimental.pnpSourceMap option is enabled in next.config.js and the inputSourceMap option is passed to the SWC loader in webpack.config.js.

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

nextjs - ✅(Solved) Fix Sourcemaps broken for next/dist files in Yarn PnP mode (webpack) [1 pull requests, 1 comments, 1 participants]