nextjs - 💡(How to fix) Fix Invariant: Expected workUnitAsyncStorage to have a store during static generation (force-static) with custom webpack config / App Router [1 comments, 2 participants]

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…
GitHub stats
vercel/next.js#92656Fetched 2026-04-12 13:23:20
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

next build fails while prerendering a minimal App Router page with export const dynamic = 'force-static':

Error [InvariantError]: Invariant: Expected workUnitAsyncStorage to have a store. This is a bug in Next.js.

This occurs in a large Next 15.5.x application after a binary bisect showed the failure persists even when root app/layout.tsx is reduced to <html><body>{children}</body></html> (no CSS imports, no metadata exports, minimal head). A patch bump from 15.5.14 to 15.5.15 does not change behavior.

Error Message

Error [InvariantError]: Invariant: Expected workUnitAsyncStorage to have a store. This is a bug in Next.js.

Root Cause

next build fails while prerendering a minimal App Router page with export const dynamic = 'force-static':

Error [InvariantError]: Invariant: Expected workUnitAsyncStorage to have a store. This is a bug in Next.js.

This occurs in a large Next 15.5.x application after a binary bisect showed the failure persists even when root app/layout.tsx is reduced to <html><body>{children}</body></html> (no CSS imports, no metadata exports, minimal head). A patch bump from 15.5.14 to 15.5.15 does not change behavior.

Fix Action

Workaround

Set export const dynamic = 'force-dynamic' on the page (or parent segment) to skip static prerender for that route.

Code Example

Error [InvariantError]: Invariant: Expected workUnitAsyncStorage to have a store. This is a bug in Next.js.

---

export const dynamic = 'force-static';
export default function Page() {
  return <p>repro</p>;
}
RAW_BUFFERClick to expand / collapse

Description

next build fails while prerendering a minimal App Router page with export const dynamic = 'force-static':

Error [InvariantError]: Invariant: Expected workUnitAsyncStorage to have a store. This is a bug in Next.js.

This occurs in a large Next 15.5.x application after a binary bisect showed the failure persists even when root app/layout.tsx is reduced to <html><body>{children}</body></html> (no CSS imports, no metadata exports, minimal head). A patch bump from 15.5.14 to 15.5.15 does not change behavior.

Expected behavior

Static prerender of a trivial RSC page succeeds, or a clear documented constraint explains why force-static is unsupported in this configuration.

Actual behavior

Build exits non-zero during "Generating static pages" for the route using force-static.

Workaround

Set export const dynamic = 'force-dynamic' on the page (or parent segment) to skip static prerender for that route.

Environment

  • Next.js: 15.5.15 (also observed on 15.5.14)
  • OS: Windows / Linux
  • next.config: failure appears tied to the full app configuration (custom webpack with React/Emotion dedupe aliases, compiler.emotion, experimental flags). A standalone public repro repo can be published later if maintainers need it; narrowing is easiest by incrementally copying next.config from a failing app into [email protected] until the invariant appears.

Reproduction (without a separate public repo yet)

  1. Use a Next 15.5.x App Router app with a non-trivial next.config (webpack aliases for react / react-dom / Emotion, compiler.emotion, experimental.cssChunking: 'strict', etc.—as in a typical large MUI + Emotion setup).
  2. Add app/<any>/page.tsx with:
export const dynamic = 'force-static';
export default function Page() {
  return <p>repro</p>;
}
  1. Run npm run build — expect workUnitAsyncStorage during static generation for that route.

We can follow up with a minimal public GitHub repository if triage requires it.

extent analysis

TL;DR

Setting export const dynamic = 'force-dynamic' on the page or parent segment can serve as a workaround to skip static prerender for that route.

Guidance

  • The error message suggests an issue with workUnitAsyncStorage during static generation, which might be related to the force-static configuration.
  • To verify the issue, try reproducing it with a minimal next.config and then incrementally add configurations until the error appears.
  • Consider creating a minimal public GitHub repository to help maintainers reproduce and debug the issue.
  • As a temporary workaround, setting export const dynamic = 'force-dynamic' can allow the build to succeed, but this may not be the desired behavior.

Example

No code example is provided as the issue already includes a clear reproduction steps and code snippets.

Notes

The root cause of the issue is unclear, and more information or a minimal reproduction repository may be needed to fully diagnose and fix the problem.

Recommendation

Apply the workaround by setting export const dynamic = 'force-dynamic' on the affected pages, as this allows the build to succeed, although it may not be the desired behavior. This is recommended because it provides a temporary solution to the build failure, and further investigation can be done to find a more permanent fix.

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

Static prerender of a trivial RSC page succeeds, or a clear documented constraint explains why force-static is unsupported in this configuration.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING