nextjs - 💡(How to fix) Fix Build fails with 'Html should not be imported outside of pages/_document' error in internal webpack chunk during error page static generation (v15.5.6) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

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#86177Fetched 2026-04-08 02:12:12
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

Error Message

Error: <Html> should not be imported outside of pages/_document.
    at x (.next/server/chunks/5611.js:6:1351)
Error occurred prerendering page "/404"

Root Cause

The error occurs in .next/server/chunks/5611.js:6:1351, which appears to contain OpenTelemetry-related code that Next.js internally generates during the build process. This chunk incorrectly attempts to import Html from next/document during error page static generation.

Fix Action

Fix / Workaround

  • Cannot build for production
  • Cannot deploy to Vercel or any other platform
  • All PRs failing CI due to build failure
  • No workaround available

Code Example

Error: <Html> should not be imported outside of pages/_document.
    at x (.next/server/chunks/5611.js:6:1351)
Error occurred prerendering page "/404"

---

{
  output: 'standalone',
  reactStrictMode: true,
  skipTrailingSlashRedirect: true,
  experimental: {
    optimizeCss: true,
    optimizePackageImports: ['lucide-react', '@radix-ui/react-icons'],
  },
  serverExternalPackages: [
    'discord.js',
    'whatsapp-web.js',
    'imap-simple',
    'zlib-sync',
    '@discordjs/ws',
  ],
}
RAW_BUFFERClick to expand / collapse

Bug Description

Production builds fail during static page generation with an Html import error originating from an internal Next.js webpack chunk, not from application code.

Error Message

Error: <Html> should not be imported outside of pages/_document.
    at x (.next/server/chunks/5611.js:6:1351)
Error occurred prerendering page "/404"

Environment

  • Next.js Version: 15.5.6
  • React Version: 18.3.1
  • Node Version: Latest LTS
  • Platform: macOS (Darwin 24.6.0)
  • Package Manager: npm
  • Build Command: npm run build / next build
  • Router: App Router

Reproduction Steps

  1. Create Next.js 15.5.6 App Router project
  2. Add custom app/global-error.tsx with proper structure (or use default)
  3. Run npm run build
  4. Build fails during "Generating static pages" phase at /404 or /_global-error

Expected Behavior

Build should complete successfully and generate static error pages.

Actual Behavior

Build fails immediately when attempting to generate static error pages with Html import error in internal Next.js webpack chunk 5611.js.

Investigation Summary

Critical Finding: The error originates from Next.js internal code, not from application code.

Attempted Fixes (All Failed)

  1. Removed all custom error pages (Next.js auto-generates internal /_global-error)
  2. Disabled all client providers (Rollbar, Statsig, SessionProvider, Honeybadger)
  3. Removed instrumentation.ts
  4. Disabled all experimental features
  5. Removed @vercel/otel package
  6. Added export const dynamic = "force-dynamic" to all error pages
  7. Clean cache rebuilds (rm -rf .next)
  8. Simplified global-error.tsx to minimal code
  9. Removed CSS modules from error pages
  10. Disabled BotID wrapper in next.config.ts

Error persists in all scenarios, even with:

  • No custom global-error.tsx file
  • Minimal next.config.ts
  • No providers or third-party integrations
  • Fresh .next directory

Root Cause Analysis

The error occurs in .next/server/chunks/5611.js:6:1351, which appears to contain OpenTelemetry-related code that Next.js internally generates during the build process. This chunk incorrectly attempts to import Html from next/document during error page static generation.

Additional Context

  • Build compiles successfully (~20-25 seconds)
  • Failure occurs during "Generating static pages (0/63)"
  • Fails immediately when reaching /404 or /_global-error
  • The internal chunk 5611.js is not part of our application code
  • This appears to be related to Next.js's internal error handling system

Impact

Severity: CRITICAL - Blocks all production deployments

  • Cannot build for production
  • Cannot deploy to Vercel or any other platform
  • All PRs failing CI due to build failure
  • No workaround available

Next.js Config

{
  output: 'standalone',
  reactStrictMode: true,
  skipTrailingSlashRedirect: true,
  experimental: {
    optimizeCss: true,
    optimizePackageImports: ['lucide-react', '@radix-ui/react-icons'],
  },
  serverExternalPackages: [
    'discord.js',
    'whatsapp-web.js',
    'imap-simple',
    'zlib-sync',
    '@discordjs/ws',
  ],
}

Request

Please investigate the internal webpack chunk generation for error pages in Next.js 15.5.6. The Html import error is occurring in Next.js framework code, not in application code, making it impossible to work around.

extent analysis

TL;DR

The most likely fix is to upgrade Next.js to a version where this internal error is resolved or to apply a workaround by modifying the Next.js configuration to avoid the problematic internal chunk generation.

Guidance

  • Investigate if there's an existing issue or fix in newer versions of Next.js that addresses the internal Html import error in the webpack chunk.
  • Try modifying the next.config.js file to exclude or customize the generation of the internal chunk that's causing the error, potentially by adjusting the experimental or serverExternalPackages configurations.
  • Verify if the error persists when disabling specific experimental features or external packages to isolate the root cause.
  • Consider reaching out to the Next.js community or support for further assistance, as the error is occurring within the framework's internal code.

Example

No specific code example can be provided without guessing the exact fix, but modifying the next.config.js to adjust experimental features might look something like this:

experimental: {
  // Try disabling optimizeCss or optimizePackageImports
  // optimizeCss: false,
  // optimizePackageImports: [],
}

Notes

The provided information suggests that the error is internal to Next.js and not directly related to the application code. Therefore, any fix or workaround might require updates to Next.js itself or adjustments to how the framework is configured.

Recommendation

Apply a workaround by modifying the Next.js configuration, as upgrading to a fixed version is not explicitly mentioned as an option in the issue. The reason is that the issue seems to be related to the internal workings of Next.js 15.5.6, and without a clear indication of a fixed version, adjusting the configuration to avoid the error might be the most straightforward approach.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING