nextjs - 💡(How to fix) Fix [Bug] 16.2.x standalone tracing misses transitive deps of custom cacheHandler in pnpm monorepo (Vercel runtime ERR_MODULE_NOT_FOUND)

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…

In a pnpm monorepo using a shared custom cacheHandler, deployment runtime can fail with ERR_MODULE_NOT_FOUND for transitive imports from the cache handler module, even when build succeeds.

This appears in 16.2.x after multiple tracing/standalone changes landed in that train (for example "include fewer traced files for standalone" and "inline handler dependencies instead of tracing").

Root Cause

In a pnpm monorepo using a shared custom cacheHandler, deployment runtime can fail with ERR_MODULE_NOT_FOUND for transitive imports from the cache handler module, even when build succeeds.

This appears in 16.2.x after multiple tracing/standalone changes landed in that train (for example "include fewer traced files for standalone" and "inline handler dependencies instead of tracing").

Fix Action

Fix / Workaround

Workaround used

Code Example

n/a
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

n/a

To Reproduce

Summary

In a pnpm monorepo using a shared custom cacheHandler, deployment runtime can fail with ERR_MODULE_NOT_FOUND for transitive imports from the cache handler module, even when build succeeds.

This appears in 16.2.x after multiple tracing/standalone changes landed in that train (for example "include fewer traced files for standalone" and "inline handler dependencies instead of tracing").

Versions

  • Works in our setup: 16.1.4
  • Fails in our setup: 16.2.6 16.1.4 release is minimal and does not mention tracing/standalone behavior changes.

Environment

  • pnpm monorepo
  • App consumes shared next-configs package
  • Shared config sets cacheHandler via require.resolve('next-configs/cache-handler.mjs')
  • Deployment target where runtime has only traced artifacts (e.g. Vercel /var/task)

Symptoms

Runtime logs show:

  • First: missing cache-handler.mjs in deployment artifact
  • Then (after forcing that file): missing package imported by that handler, e.g. @fortedigital/nextjs-cache-handler Build still succeeds locally and in CI.

Why this looks like a tracing gap

When we explicitly include:

  • the handler file, and
  • package roots for handler imports (@fortedigital/nextjs-cache-handler, redis) the generated traced manifests include those paths and runtime failure is resolved in our setup.

Expected behavior

If cacheHandler is configured, Next tracing for standalone/deployment artifacts should include:

  1. The handler file, and
  2. Transitive runtime package dependencies required by that handler without requiring manual outputFileTracingIncludes entries.

Actual behavior

Tracing may include the handler file but omit transitive package deps, causing deployment-only runtime failure (ERR_MODULE_NOT_FOUND).

Workaround used

Manual/derived outputFileTracingIncludes['/*'] additions for:

  • Handler file
  • Package roots used by imports inside handler file This is fragile and app-specific.

Related upstream context

  • #88322 — Turbopack: include fewer traced files for standalone
  • #89269 — Inline handler dependencies instead of tracing
  • #89508 — Ensure module contexts are always included in adapter traces
  • #91236 — Wire cache handlers in edge paths + regression coverage
  • Related open standalone/workspace issues: #68699, #83294

Request

Please confirm intended behavior for custom cacheHandler tracing in monorepo standalone/deployment output and consider adding regression coverage for:

  • Workspace/shared cacheHandler module
  • Transitive package import resolution in deployment artifact runtime

Current vs. Expected behavior

n/a

Provide environment information

n/a

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

Not sure

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

next build (local), Vercel (Deployed)

Additional context

No response

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…

FAQ

Expected behavior

If cacheHandler is configured, Next tracing for standalone/deployment artifacts should include:

  1. The handler file, and
  2. Transitive runtime package dependencies required by that handler without requiring manual outputFileTracingIncludes entries.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING