From 9bdbb51f4fccbd544e8d919fa78d1ad8464cb9e1 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 9 Apr 2025 19:55:05 -0700 Subject: [PATCH] =?UTF-8?q?Turbopack:=20don=E2=80=99t=20warn=20about=20web?= =?UTF-8?q?pack=20being=20configured=20when=20`experimental.turbo`=20is=20?= =?UTF-8?q?set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a regression introduced in 15.3.0 by #77850, when `config.experimental.turbo` was moved to `config.turbopack`. We still support `config.experimental.turbo` as well, so don’t warn when that is used. Test Plan: Added tests for this warning message and each of the unset/turbopack/experimental.turbo cases --- packages/next/src/lib/turbopack-warning.ts | 4 +- test/e2e/config-turbopack/index.test.ts | 96 ++++++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 test/e2e/config-turbopack/index.test.ts 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) + }) + }) +})