Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in next export when serverActions is enabled #50039

Merged
merged 4 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/next/src/cli/next-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const nextExport: CliCommand = (argv) => {
outdir: args['--outdir'] ? resolve(args['--outdir']) : join(dir, 'out'),
isInvokedFromCli: true,
hasAppDir: false,
buildExport: false,
styfle marked this conversation as resolved.
Show resolved Hide resolved
}

exportApp(dir, options, nextExportCliSpan)
Expand Down
9 changes: 9 additions & 0 deletions packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ export default async function exportApp(
)
}

// Running next export or using output: 'export' in next.config.js
if (!options.buildExport || nextConfig.output === 'export') {
if (nextConfig.experimental.serverActions) {
throw new ExportError(
styfle marked this conversation as resolved.
Show resolved Hide resolved
`Server Actions are not supported with static export.`
)
}
}

const telemetry = options.buildExport ? null : new Telemetry({ distDir })

if (telemetry) {
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/lib/metadata/resolve-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ describe('accumulateMetadata', () => {
[{ themeColor: '#fff' }, null],
]
const metadata = await accumulateMetadata(metadataItems)
console.log('xxmetadata', metadata.themeColor)
expect(metadata).toMatchObject({
themeColor: [{ color: '#fff' }],
})
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/app-dir/actions/app-action-export.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createNextDescribe } from 'e2e-utils'

createNextDescribe(
'app-dir action handling - next export',
{
files: __dirname,
skipStart: true,
skipDeployment: true,
},
({ next, isNextStart }) => {
if (!isNextStart) {
it('skip test for dev mode', () => {})
return
}

beforeAll(async () => {
await next.stop()
await next.patchFile(
'next.config.js',
`
module.exports = {
output: 'export',
experimental: {
serverActions: true,
},
}
`
)
try {
await next.start()
} catch {}
})

it('should error when use export output for server actions', async () => {
expect(next.cliOutput).toContain(
`Server Actions are not supported with static export.`
)
})
}
)
2 changes: 1 addition & 1 deletion test/lib/next-modes/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Span } from 'next/src/trace'
import { NextInstance } from './base'

export class NextDevInstance extends NextInstance {
private _cliOutput: string
private _cliOutput: string = ''

public get buildId() {
return 'development'
Expand Down
9 changes: 5 additions & 4 deletions test/lib/next-modes/next-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Span } from 'next/src/trace'

export class NextStartInstance extends NextInstance {
private _buildId: string
private _cliOutput: string
private _cliOutput: string = ''
private spawnOpts: SpawnOptions

public get buildId() {
Expand Down Expand Up @@ -37,9 +37,6 @@ export class NextStartInstance extends NextInstance {
}

public async start() {
if (this.childProcess) {
throw new Error('next already started')
}
this._cliOutput = ''
this.spawnOpts = {
cwd: this.testDir,
Expand All @@ -53,6 +50,10 @@ export class NextStartInstance extends NextInstance {
__NEXT_TEST_MODE: 'e2e',
},
}

if (this.childProcess) {
throw new Error('next already started')
huozhi marked this conversation as resolved.
Show resolved Hide resolved
}
let buildArgs = ['yarn', 'next', 'build']
let startArgs = ['yarn', 'next', 'start']

Expand Down