Repository navigation
Next.js <> Turbopack Error - Module 52042 was instantiated because it was required from module 15861, but the module factory is not available. #98131
Replies: 3 comments 1 reply
|
This is deployment skew, and the fact that appending builds to S3 doesn't fix it is expected — the problem isn't missing chunk files, it's a stale HTML document. What's happening: the user's browser holds an HTML/RSC payload from build A, which references a specific module graph. When they navigate client-side after build B ships, the router fetches a build-B RSC payload or chunk. Module IDs in Turbopack are content-derived and not stable across builds, so module 52042 in build B's graph is a different module than build A's runtime expects. Both files exist in S3 — they just describe incompatible graphs. That's why keeping old builds doesn't help. Why local repro failed: overwriting the build locally also invalidates your dev/preview HTML, so the browser gets a consistent pair. The skew only shows up when the document is old and the fetch is new. To reproduce: load the page, run a new build with a changed component, deploy it, then click a client-side link on the still-open tab without reloading. The actual fix — // next.config.js
module.exports = {
deploymentId: process.env.DEPLOYMENT_ID, // e.g. CODEBUILD_RESOLVED_SOURCE_VERSION
}Set Things to check alongside it:
With |
|
One important caveat for the proposed The documented mechanism has two different parts:
A pure S3/CloudFront static export has no Next.js server to perform the header comparison. Therefore For this deployment model I would first verify whether the pipeline is publishing a true
If seamless recovery of old client navigations is a hard requirement, use a Next.js server with Official behavior: https://nextjs.org/docs/app/api-reference/config/next-config-js/deploymentId |
|
This is version skew, and it's an expected side effect of code-splitting combined with rolling/appended deployments — not a Turbopack bug. It's officially documented under Next.js's Self-Hosting guide. Here's the mechanism: a user has your page open from build N. That page's client runtime has a module graph tied to build N's chunk hashes. When something on that page triggers a lazy/dynamic import (route prefetch, a The fix Next.js ships for exactly this is the module.exports = { With this set, Next.js tags requests with the deployment ID and detects a mismatch between the client's ID and the server's. When it detects skew, it forces a hard navigation (full page reload) instead of attempting a broken client-side transition — so instead of crashing mid-navigation, the user just gets a normal reload onto the current build. One caveat specific to your setup, called out directly in the docs: a |
Uh oh!
There was an error while loading. Please reload this page.
Summary
We have a landing page which only has static pages for now and we are deploying it using AWS CodePipeline which just builds the pages and puts it in a S3 bucket which is then served using AWS CloudFront.
These builds are appended into S3 and we don't delete the previous build modules for now.
We are facing a deployment Skew here. So lets say a user is on page and a new deployment is published, some of the users face this "Module X was instantiated because it was required from module Y, but the module factory is not available." error. I tried to reproduce this issue locally but couldn't with the condition that we have for the production deployment, though I was able to replicate this issue by replacing the requested chunk with some other chunk and got the same error.
But I'm not sure if this is what is happening in the production deployment as I tried changing the content in the local, rebuild it and then overwrite the current existing build such that the chunk hash changes to replicate the issue but it worked fine as it gets new updated page from the build.
I have already saw a few discussion related to this and checked for the wrong patterns that were mentioned and we aren't following any of them.
Additional information
No response
Example
No response
All reactions