Skip to content

Conversation

@buley
Copy link

@buley buley commented Jan 16, 2026

When building Next.js 16+ apps for Cloudflare Workers, the build fails with 50+ module resolution errors like:

  • Could not resolve "./lib/incremental-cache"
  • Could not resolve "./lib/trace/tracer"
  • Could not resolve "./lib/router-utils/is-postpone"

Root Cause

Next.js 16 changed the internal file structure. NFT (Node File Tracing) used by copyTracedFiles doesn't follow all internal require chains, resulting in an incomplete next/dist/ directory being copied to the output. Only ~5 files were being copied instead of the 176+ required.

Solution

After copyTracedFiles runs, copy the complete next/dist/ directory from the actual workspace node_modules (not the standalone output) to ensure all internal modules are available. This is only done for Next.js 16+.

Changes:

  • Added copyMissingNextDistDirs() function to createServerBundle.ts
  • Function runs only for Next.js 16+
  • Copies the complete next/dist/ directory from the source installation
  • Handles both standard and monorepo setups (bun, pnpm, npm)
  • Resolves symlinks correctly for bun/pnpm hoisted node_modules

Testing:

  • Tested with Next.js 16.1.1 in a bun monorepo
  • Build completes successfully (previous 49+ module errors resolved)
  • Only unrelated project-specific errors remain

workers-frameworks and others added 3 commits January 16, 2026 18:09
@changeset-bot
Copy link

changeset-bot bot commented Jan 16, 2026

⚠️ No Changeset found

Latest commit: 11b642f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vicb
Copy link
Contributor

vicb commented Jan 17, 2026

May I ask if the PR was AI generated?
To be clear I have no problem with using AI to generate PRs - I use it myself and it can help.

However AI sometimes is wrong about the root cause analysis and while what it generates "work", it is definitely not the right thing to do. It looks to me it's what happened here.

Anyway, could you please create an issue with a repro so that we can take a look at what the actual issue is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants