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

only log export-no-custom-routes warning if unsupported #57298

Merged
merged 8 commits into from
Oct 23, 2023
32 changes: 18 additions & 14 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { pathHasPrefix } from '../shared/lib/router/utils/path-has-prefix'

import { ZodParsedType, util as ZodUtil } from 'next/dist/compiled/zod'
import type { ZodError, ZodIssue } from 'next/dist/compiled/zod'
import { hasNextSupport } from '../telemetry/ci-info'

export { normalizeConfig } from './config-shared'
export type { DomainLocale, NextConfig } from './config-shared'
Expand Down Expand Up @@ -257,20 +258,23 @@ function assignDefaults(
'Specified "i18n" cannot be used with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-i18n'
)
}
if (result.rewrites) {
throw new Error(
'Specified "rewrites" cannot be used with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
)
}
if (result.redirects) {
throw new Error(
'Specified "redirects" cannot be used with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
)
}
if (result.headers) {
throw new Error(
'Specified "headers" cannot be used with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
)

if (!hasNextSupport) {
if (result.rewrites) {
Log.warn(
'Specified "rewrites" will not automatically work with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
)
}
if (result.redirects) {
Log.warn(
'Specified "redirects" will not automatically work with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
)
}
if (result.headers) {
Log.warn(
'Specified "headers" will not automatically work with "output: export". See more info here: https://nextjs.org/docs/messages/export-no-custom-routes'
)
}
}
}

Expand Down
101 changes: 74 additions & 27 deletions test/integration/config-output-export/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,86 @@ describe('config-output-export', () => {
)
})

it('should error with "rewrites" config', async () => {
const { stderr } = await runDev({
output: 'export',
rewrites: [{ source: '/from', destination: '/to' }],
describe('when hasNextSupport = false', () => {
it('should error with "rewrites" config', async () => {
const { stderr } = await runDev({
output: 'export',
rewrites: [{ source: '/from', destination: '/to' }],
})
expect(stderr).toContain(
'Specified "rewrites" will not automatically work with "output: export".'
)
})
expect(stderr).toContain(
'Specified "rewrites" cannot be used with "output: export".'
)
})

it('should error with "redirects" config', async () => {
const { stderr } = await runDev({
output: 'export',
redirects: [{ source: '/from', destination: '/to', permanent: true }],
it('should error with "redirects" config', async () => {
const { stderr } = await runDev({
output: 'export',
redirects: [{ source: '/from', destination: '/to', permanent: true }],
})
expect(stderr).toContain(
'Specified "redirects" will not automatically work with "output: export".'
)
})

it('should error with "headers" config', async () => {
const { stderr } = await runDev({
output: 'export',
headers: [
{
source: '/foo',
headers: [{ key: 'x-foo', value: 'val' }],
},
],
})
expect(stderr).toContain(
'Specified "headers" will not automatically work with "output: export".'
)
})
expect(stderr).toContain(
'Specified "redirects" cannot be used with "output: export".'
)
})

it('should error with "headers" config', async () => {
const { stderr } = await runDev({
output: 'export',
headers: [
{
source: '/foo',
headers: [{ key: 'x-foo', value: 'val' }],
},
],
describe('when hasNextSupport = true', () => {
beforeAll(() => {
process.env.NOW_BUILDER = '1'
})

afterAll(() => {
delete process.env.NOW_BUILDER
})

it('should error with "rewrites" config', async () => {
const { stderr } = await runDev({
output: 'export',
rewrites: [{ source: '/from', destination: '/to' }],
})
expect(stderr).not.toContain(
'Specified "rewrites" will not automatically work with "output: export".'
)
})

it('should error with "redirects" config', async () => {
const { stderr } = await runDev({
output: 'export',
redirects: [{ source: '/from', destination: '/to', permanent: true }],
})
expect(stderr).not.toContain(
'Specified "redirects" will not automatically work with "output: export".'
)
})

it('should error with "headers" config', async () => {
const { stderr } = await runDev({
output: 'export',
headers: [
{
source: '/foo',
headers: [{ key: 'x-foo', value: 'val' }],
},
],
})
expect(stderr).not.toContain(
'Specified "headers" will not automatically work with "output: export".'
)
})
expect(stderr).toContain(
'Specified "headers" cannot be used with "output: export".'
)
})

it('should error with api routes function', async () => {
Expand Down