diff --git a/packages/next/src/lib/turbopack-warning.ts b/packages/next/src/lib/turbopack-warning.ts index 981ade96cc3cb..3cf52c33e6985 100644 --- a/packages/next/src/lib/turbopack-warning.ts +++ b/packages/next/src/lib/turbopack-warning.ts @@ -144,7 +144,7 @@ export async function validateTurboNextConfig({ if (key.startsWith('webpack') && rawNextConfig.webpack) { hasWebpackConfig = true } - if (key.startsWith('turbopack')) { + if (key.startsWith('turbopack') || key.startsWith('experimental.turbo')) { hasTurboConfig = true } @@ -180,7 +180,7 @@ export async function validateTurboNextConfig({ `Webpack is configured while Turbopack is not, which may cause problems.` ) Log.warn( - `See instructions if you need to configure Turbopack:\n https://nextjs.org/docs/app/api-reference/next-config-js/turbo\n` + `See instructions if you need to configure Turbopack:\n https://nextjs.org/docs/app/api-reference/next-config-js/turbopack\n` ) } diff --git a/test/e2e/config-turbopack/index.test.ts b/test/e2e/config-turbopack/index.test.ts new file mode 100644 index 0000000000000..36dacfd63a972 --- /dev/null +++ b/test/e2e/config-turbopack/index.test.ts @@ -0,0 +1,96 @@ +/* eslint-disable jest/no-standalone-expect */ +import { nextTestSetup } from 'e2e-utils' + +const WARNING_MESSAGE = 'Webpack is configured while Turbopack is not' + +const itif = (condition: boolean) => (condition ? it : it.skip) + +describe('config-turbopack', () => { + describe('when webpack is configured but Turbopack is not', () => { + const { next, isTurbopack } = nextTestSetup({ + files: { + 'app/page.js': ` + export default function Page() { + return

hello world

+ } + `, + 'next.config.js': ` + module.exports = { + webpack: (config) => { + return config + }, + } + `, + }, + }) + + itif(isTurbopack)('warns', async () => { + if (next) await next.render('/') + expect(next.cliOutput).toContain(WARNING_MESSAGE) + }) + }) + + describe('when webpack is configured and config.turbopack is set', () => { + const { next, isTurbopack } = nextTestSetup({ + files: { + 'app/page.js': ` + export default function Page() { + return

hello world

+ } + `, + 'next.config.js': ` + module.exports = { + turbopack: { + rules: { + '*.foo': { + loaders: ['foo-loader'] + } + } + }, + webpack: (config) => { + return config + }, + } + `, + }, + }) + + itif(isTurbopack)('does not warn', async () => { + if (next) await next.render('/') + expect(next.cliOutput).not.toContain(WARNING_MESSAGE) + }) + }) + + describe('when webpack is configured and config.experimental.turbo is set', () => { + const { next, isTurbopack } = nextTestSetup({ + files: { + 'app/page.js': ` + export default function Page() { + return

hello world

+ } + `, + 'next.config.js': ` + module.exports = { + experimental: { + turbo: { + rules: { + '*.foo': { + loaders: ['foo-loader'] + } + } + } + }, + webpack: (config) => { + return config + }, + } + `, + }, + }) + + itif(isTurbopack)('does not warn', async () => { + if (next) await next.render('/') + expect(next.cliOutput).not.toContain(WARNING_MESSAGE) + }) + }) +})