nextjs - 💡(How to fix) Fix MIDDLEWARE_INVOCATION_FAILED + FUNCTION_INVOCATION_FAILED on Vercel deploy: Cannot find module @swc/helpers/esm/_interop_require_default.js (next 16.2.x + proxy.ts middleware)

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…

Error Message

Minimal reproduction in the linked branch: the single file rename git mv src/proxy.ts src/proxy.ts.disabled reproduces the crash (with error code FUNCTION_INVOCATION_FAILED instead of MIDDLEWARE_INVOCATION_FAILED, but identical stack trace), proving the caller is not application code. The error code depends on which Vercel function handles the request: The function should serve requests without a missing-module error, or the build pipeline should emit a clear error before deploy if a runtime dependency is unsatisfiable.

  • Renaming src/proxy.ts away (no middleware): error code changes to FUNCTION_INVOCATION_FAILED on / with identical stack trace — decisively falsifies any application-code-level caller

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0
Binaries:
  Node: 20.x
  npm: 10.x
Relevant Packages:
  next: 16.2.6 (also reproduced on 16.2.5)
  @sentry/nextjs: 10.48.0 (also reproduced after fresh-install bump to 10.53.1)
  @swc/helpers: 0.5.21 (overridden + explicit dependency)
  @supabase/ssr: 0.9.0
  @supabase/supabase-js: 2.105.4 (after fresh install) / 2.99.0 (before)
  @supabase/postgrest-js: 2.105.4 / 2.99.0
  next-intl: 4.8.3
  next-pwa: 5.6.0
  @react-pdf/renderer: 4.3.2
Next.js Config:
  output: <default>
  File convention: src/proxy.ts (Next.js 16 new convention)
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/Makturk/shade-quote/tree/s24-d1-step3-middleware-disabled-test

To Reproduce

  1. Take any Next.js 16.2.x App Router project with:
    • src/proxy.ts (Next.js 16 middleware convention)
    • @sentry/nextjs in dependencies (does not need to be wired into config — package presence alone reproduces)
    • @swc/helpers as transitive or explicit dep at any 0.5.x version
  2. next build locally (succeeds — no warnings).
  3. Deploy to Vercel (any framework preset "Next.js", any region, any plan).
  4. Request / or any route.

Minimal reproduction in the linked branch: the single file rename git mv src/proxy.ts src/proxy.ts.disabled reproduces the crash (with error code FUNCTION_INVOCATION_FAILED instead of MIDDLEWARE_INVOCATION_FAILED, but identical stack trace), proving the caller is not application code.

Current vs. Expected behavior

Current behavior

Every Vercel deploy (preview and production) fails at function invocation time with: Cannot find module '/var/task/node_modules/@swc/helpers/esm/_interop_require_default.js' Did you forget to add it to "dependencies" in package.json? Node.js process exited with exit status: 1.

The error code depends on which Vercel function handles the request:

  • MIDDLEWARE_INVOCATION_FAILED when src/proxy.ts exists
  • FUNCTION_INVOCATION_FAILED on / when src/proxy.ts is renamed away

The crash is therefore not specific to the middleware function — it affects every Vercel function execution path served by the app.

The local Next.js build artifact contains zero references to @swc/helpers and zero references to @sentry/* in the middleware path after removing every Sentry reference from application code. Source maps for the Edge chunks list only 7 sources total, none of which are @swc/helpers or @sentry/*. Despite this, Vercel's deploy artifact still attempts to require @swc/helpers/esm/_interop_require_default.js at runtime.

node_modules/@swc/helpers/esm/_interop_require_default.js exists locally before and after every fresh npm install we ran. The @swc/helpers exports map keys module-sync / webpack / import all point to ESM, but Next.js's NFT trace (.next/server/middleware.js.nft.json) only lists the CJS variant (cjs/_interop_require_default.cjs).

Expected behavior

The function should serve requests without a missing-module error, or the build pipeline should emit a clear error before deploy if a runtime dependency is unsatisfiable.

Falsification chain (5.5h, 11 hypotheses tested)

Full evidence: https://github.com/Makturk/shade-quote/blob/s24-d1-step3-closeout-docs/docs/sprints/2026-sprint-24/step-3-vercel-support-evidence.md

Summary:

  • Vercel Framework Preset already "Next.js"; Build Cache Clear does not help
  • outputFileTracingIncludes does not affect the middleware NFT (consistent with docs note that Edge Runtime routes are not affected)
  • withSentryConfig opts (autoInstrumentMiddleware, excludeServerRoutes) do not remove Sentry from the Edge bundle
  • Dropping withSentryConfig wrapper + emptying sentry.edge.config.ts left the Edge chunk source map listing 50+ @sentry/core files (top-level import * as Sentry in instrumentation.ts)
  • Lazy import('@sentry/nextjs') inside an if (process.env.NEXT_RUNTIME === 'nodejs') guard makes the Edge bundle LARGER (Turbopack cannot statically evaluate runtime env checks; bundled @sentry/* defensively, 432KB → 2.4MB)
  • Removing every Sentry reference from instrumentation.ts reduced the Edge bundle to 100 KB with mathematical zero @sentry/@swc/helpers source map entries. Same crash on Vercel.
  • Vercel Sentry integration not installed; deleting all SENTRY_* env vars + cache clear: same crash
  • Renaming src/proxy.ts away (no middleware): error code changes to FUNCTION_INVOCATION_FAILED on / with identical stack trace — decisively falsifies any application-code-level caller
  • Downgrading to [email protected]: same crash
  • rm -rf node_modules package-lock.json && npm install (bumps Sentry 10.48→10.53, Supabase 2.99→2.105, drops 4 HIGH vulns): same crash

Why we believe this is a framework/platform bundling issue

Same module path missing across two distinct function types (middleware function AND page-render function) with identical stack trace points to the framework runtime bundling layer beneath both function types. Local Turbopack output is clean; only Vercel's deploy-time pipeline produces the missing runtime require.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0
Binaries:
  Node: 20.x
  npm: 10.x
Relevant Packages:
  next: 16.2.6 (also reproduced on 16.2.5)
  @sentry/nextjs: 10.48.0 (also reproduced after fresh-install bump to 10.53.1)
  @swc/helpers: 0.5.21 (overridden + explicit dependency)
  @supabase/ssr: 0.9.0
  @supabase/supabase-js: 2.105.4 (after fresh install) / 2.99.0 (before)
  @supabase/postgrest-js: 2.105.4 / 2.99.0
  next-intl: 4.8.3
  next-pwa: 5.6.0
  @react-pdf/renderer: 4.3.2
Next.js Config:
  output: <default>
  File convention: src/proxy.ts (Next.js 16 new convention)

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

Runtime

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

Vercel (Deployed)

Additional context

Hosting: Vercel (Hobby plan, region fra1).

Tested canary: No. The production project cannot afford a canary rollout while debugging — will test canary if maintainers request.

Branches preserved as evidence (linked Repository):

  • s24-d1-step3-middleware-disabled-test (commit 39af0622) — minimal repro
  • s24-d1-step3-sentry-middleware-disable (commit 81dad749) — Sentry mathematical zero
  • s24-d1-step3-next-16-2-5-test (commit bc55c5d7) — version falsification
  • s24-d1-step3-lockfile-regen-test (commit 71b3cce3) — fresh install falsification + 4 HIGH vuln drop

Full forensic documentation: https://github.com/Makturk/shade-quote/blob/s24-d1-step3-closeout-docs/docs/sprints/2026-sprint-24/step-3-vercel-support-evidence.md

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

The function should serve requests without a missing-module error, or the build pipeline should emit a clear error before deploy if a runtime dependency is unsatisfiable.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix MIDDLEWARE_INVOCATION_FAILED + FUNCTION_INVOCATION_FAILED on Vercel deploy: Cannot find module @swc/helpers/esm/_interop_require_default.js (next 16.2.x + proxy.ts middleware)