diff --git a/packages/next/src/server/config.ts b/packages/next/src/server/config.ts index 8f32e0c08159e..8184ecfb71fa7 100644 --- a/packages/next/src/server/config.ts +++ b/packages/next/src/server/config.ts @@ -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' @@ -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' + ) + } } } diff --git a/test/integration/config-output-export/test/index.test.ts b/test/integration/config-output-export/test/index.test.ts index 3389cd8a316ed..bd826f531886e 100644 --- a/test/integration/config-output-export/test/index.test.ts +++ b/test/integration/config-output-export/test/index.test.ts @@ -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 () => {