Skip to content

Stale js chunk referencing non-existant content after updating next.js. Filename hash not changing even though content has changed. #78756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MartinDavi opened this issue May 1, 2025 · 2 comments
Labels
Webpack Related to Webpack with Next.js.

Comments

@MartinDavi
Copy link

MartinDavi commented May 1, 2025

Link to the code that reproduces this issue

https://github.com/MartinDavi/nextjs-reproduction

To Reproduce

  1. Checkout repo
  2. npm install
  3. npm run build
  4. Take note of the last two filenames in .next/static/chunks/ - reactPlayerYouTube.[contenthash].js and webpack.[chunkhash].js
  5. Update to next.js v15.3.0
  6. Run npm build again.
  7. Go look at those same two file names again.

Current vs. Expected behavior

What you should see is that the hash for reactPlayerYouTube has changed, but the hash for webpack has not, even though the content of webpack.[chunkhash].js has changed.

What this has resulted in is that we pushed an update to next.js to production. Any user that had previously visited the site has webpack.[chunkhash].js cached in their browser, because it gets a cache-control header of public, max-age=31536000, immutable since it's supposed to get a new hash when content changes.

But as you can see it doesn't. So for those users that already had it cached, their cached version is referencing a reactPlayerYouTube.[contenthash].js file that no longer exists on our server, since we wipe .next on deploy.

This is happening because in next.js's webpack.config.js there is this:

     filename: isNodeOrEdgeCompilation
        ? dev || isEdgeServer
          ? `[name].js`
          : `../[name].js`
        : `static/chunks/${isDevFallback ? 'fallback/' : ''}[name]${
            dev ? '' : appDir ? '-[chunkhash]' : '-[contenthash]'
          }.js`,
      // This saves chunks with the name given via `import()`
      chunkFilename: isNodeOrEdgeCompilation
        ? '[name].js'
        : `static/chunks/${isDevFallback ? 'fallback/' : ''}${
            dev ? '[name]' : '[name].[contenthash]'
          }.js`,

filename is using [chunkhash] for app router, while chunkFilename is using [contenthash].

If filename was using [contenthash] as well, I believe this would not be a problem. I may be wrong in my diagnoses, but this is certainly an issue and permanently breaks the site for repeat visitors until we ship something that gets [chunkhash] to change for that file.

Provide environment information

Relevant Packages:
  next: 15.2.5
  eslint-config-next: 15.3.1
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3

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

Webpack

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

next build (local), Other (Deployed)

@github-actions github-actions bot added the Webpack Related to Webpack with Next.js. label May 1, 2025
@RubenZx

This comment has been minimized.

@rigobauer
Copy link

We have the same issue. Everything is working perfectly with 15.2.5 but when we update to 15.3.2, some pages fail with the missing chunk error (as described, is using the old name of the chunk file).
On our case looks like the chunk is a component loaded with dynamic + { ssr: false } (just in case it helps). If we remove the component from the page or change some code on the page, then it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Webpack Related to Webpack with Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants