Skip to content

Comments

fix(nextjs): use out/ as default output dir when output is export#34530

Open
asumaran wants to merge 1 commit intonrwl:masterfrom
asumaran:fix/next-output-export-getoutputs
Open

fix(nextjs): use out/ as default output dir when output is export#34530
asumaran wants to merge 1 commit intonrwl:masterfrom
asumaran:fix/next-output-export-getoutputs

Conversation

@asumaran
Copy link

Current Behavior

The getOutputs() function in the @nx/next plugin only reads distDir from the resolved Next.js config to determine the build output directory. When a project uses output: 'export' (for static site generation), Next.js generates output in out/ by default, but the plugin ignores this and always defaults to .next/.

This causes Nx to cache/restore .next/ instead of out/, which breaks deployment pipelines that depend on the out/ directory for static export builds.

Edge cases

Config Expected output dir Before this PR After this PR
{} (default) .next .next .next
{ distDir: 'build' } build build build
{ output: 'export' } out .next out
{ output: 'export', distDir: 'custom' } custom custom custom
{ output: 'standalone' } .next .next .next

Expected Behavior

When output: 'export' is set in the Next.js config, the plugin should use out/ as the default output directory (matching Next.js behavior), unless an explicit distDir is also specified (in which case distDir takes precedence).

The priority is:

  1. Explicit distDir -> use distDir
  2. output === 'export' without distDir -> use 'out'
  3. Default -> use '.next'

Changes

  • Modified getOutputs() in packages/next/src/plugins/plugin.ts to extract a unified resolvedConfig and check for output: 'export'
  • Added 3 test cases in packages/next/src/plugins/plugin.spec.ts:
    • output: 'export' with integrated project -> outputs point to out/
    • output: 'export' with root project -> outputs point to out/
    • output: 'export' + custom distDir -> distDir takes precedence

Related Issue(s)

N/A - discovered via broken deployment pipeline when using output: 'export' in Next.js projects within an Nx monorepo.

@asumaran asumaran requested a review from a team as a code owner February 20, 2026 16:43
@asumaran asumaran requested a review from jaysoo February 20, 2026 16:43
@netlify
Copy link

netlify bot commented Feb 20, 2026

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 70aff58

@netlify
Copy link

netlify bot commented Feb 20, 2026

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 70aff58

The `getOutputs()` function in the @nx/next plugin only checked for a
custom `distDir` but ignored `output: 'export'`, which generates output
in `out/` by default according to Next.js documentation.

This caused Nx to cache/restore `.next/` instead of `out/` for static
export builds, breaking deployment pipelines.

The fix applies this priority:
1. Explicit `distDir` -> use `distDir`
2. `output === 'export'` without `distDir` -> use `'out'`
3. Default -> use `'.next'`
@asumaran asumaran force-pushed the fix/next-output-export-getoutputs branch from eae9e36 to 70aff58 Compare February 20, 2026 17:05
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.

1 participant