fix(nextjs): use out/ as default output dir when output is export#34530
Open
asumaran wants to merge 1 commit intonrwl:masterfrom
Open
fix(nextjs): use out/ as default output dir when output is export#34530asumaran wants to merge 1 commit intonrwl:masterfrom
asumaran wants to merge 1 commit intonrwl:masterfrom
Conversation
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
👷 Deploy request for nx-dev pending review.Visit the deploys page to approve it
|
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'`
eae9e36 to
70aff58
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
The
getOutputs()function in the@nx/nextplugin only readsdistDirfrom the resolved Next.js config to determine the build output directory. When a project usesoutput: 'export'(for static site generation), Next.js generates output inout/by default, but the plugin ignores this and always defaults to.next/.This causes Nx to cache/restore
.next/instead ofout/, which breaks deployment pipelines that depend on theout/directory for static export builds.Edge cases
{}(default).next.next.next{ distDir: 'build' }buildbuildbuild{ output: 'export' }out.nextout{ output: 'export', distDir: 'custom' }customcustomcustom{ output: 'standalone' }.next.next.nextExpected Behavior
When
output: 'export'is set in the Next.js config, the plugin should useout/as the default output directory (matching Next.js behavior), unless an explicitdistDiris also specified (in which casedistDirtakes precedence).The priority is:
distDir-> usedistDiroutput === 'export'withoutdistDir-> use'out''.next'Changes
getOutputs()inpackages/next/src/plugins/plugin.tsto extract a unifiedresolvedConfigand check foroutput: 'export'packages/next/src/plugins/plugin.spec.ts:output: 'export'with integrated project -> outputs point toout/output: 'export'with root project -> outputs point toout/output: 'export'+ customdistDir->distDirtakes precedenceRelated Issue(s)
N/A - discovered via broken deployment pipeline when using
output: 'export'in Next.js projects within an Nx monorepo.