nextjs - 💡(How to fix) Fix [next-rspack] Persistent cache not invalidated when .pnp.cjs changes (Yarn PnP) [1 comments, 2 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#91779Fetched 2026-04-08 01:12:03
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×2closed ×1commented ×1issue_type_added ×1

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 24.1.0
  npm: 11.3.0
  Yarn: 4.13.0
  pnpm: N/A
Relevant Packages:
  next: 16.2.1-canary.4
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
  next-rspack: 16.2.1-canary.4
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

git remote add origin https://github.com/NaamuKim/next-rspack-pnp-cache-bug.git git branch -M main git push -u origin main

To Reproduce

  1. corepack enable
  2. yarn install
  3. yarn add [email protected]
  4. cp .pnp.cjs .pnp.v2.cjs
  5. yarn add [email protected]
  6. rm -rf .next && yarn build && grep -o '4.17.[0-9]*' .next/server/app/index.html | head -1 a. 4.17.21 (correct)
  7. cp .pnp.v2.cjs .pnp.cjs && yarn build & grep -o '4.17.[0-9]*' .next/server/app/index.html | head -1 a. => 4.17.21 (wrong — should be 4.17.23)

Current vs. Expected behavior

Current behavior After last step 5, the build output still contains 4.17.21 even though .pnp.cjs now resolves lodash to 4.17.23. The persistent cache is not invalidated when .pnp.cjs changes.

Expected behavior The build output should contain 4.17.23. When .pnp.cjs changes, the rspack persistent cache should be invalidated automatically.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 24.1.0
  npm: 11.3.0
  Yarn: 4.13.0
  pnpm: N/A
Relevant Packages:
  next: 16.2.1-canary.4
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 5.9.3
  next-rspack: 16.2.1-canary.4
Next.js Config:
  output: N/A

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

Use Cache, Webpack

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

next build (local)

Additional context

This is a configuration mismatch between webpack and rspack in webpack-config.ts. webpack's persistent cache is configured via the top-level cache field, and snapshot.managedPaths / snapshot.immutablePaths are already set to handle Yarn PnP correctly (webpack-config.ts#L2282).

extent analysis

Fix Plan

To fix the issue, we need to configure rspack to invalidate its persistent cache when .pnp.cjs changes.

  • Update next.config.js to include the following configuration:
module.exports = {
  //... other configurations ...
  experimental: {
    //... other experimental configurations ...
    rspack: {
      cache: {
        // Configure rspack cache to watch for changes in .pnp.cjs
        watch: ['.pnp.cjs'],
      },
    },
  },
}

Alternatively, if you are using webpack-config.ts, you can update the cache field in the webpack configuration to include the watch option:

module.exports = {
  //... other configurations ...
  cache: {
    type: 'filesystem',
    version: '1.0',
    cacheDirectory: './.cache/webpack',
    store: 'pack',
    buildDependencies: {
      default: ['../**/*'],
    },
    hashAlgorithm: 'sha512',
    watch: ['.pnp.cjs'], // Add this line to watch for changes in .pnp.cjs
  },
}

Verification

After applying the fix, run the following commands to verify that the issue is resolved:

rm -rf .next && yarn build && grep -o '4\.17\.[0-9]*' .next/server/app/index.html | head -1

The output should contain 4.17.23, indicating that the rspack persistent cache is being invalidated correctly when .pnp.cjs changes.

Extra Tips

  • Make sure to update the cache configuration in the correct file, either next.config.js or webpack-config.ts, depending on your project setup.
  • If you are using a custom webpack configuration, ensure that the cache field is properly configured to watch for changes in .pnp.cjs.

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