diff --git a/packages/next/build/webpack/loaders/next-flight-loader/index.ts b/packages/next/build/webpack/loaders/next-flight-loader/index.ts index eeebe97d2c29791..19e91dba1899cc4 100644 --- a/packages/next/build/webpack/loaders/next-flight-loader/index.ts +++ b/packages/next/build/webpack/loaders/next-flight-loader/index.ts @@ -1,7 +1,10 @@ import { RSC_MODULE_TYPES } from '../../../../shared/lib/constants' +import { warnOnce } from '../../../../shared/lib/utils/warn-once' import { getRSCModuleType } from '../../../analysis/get-page-static-info' import { getModuleBuildInfo } from '../get-module-build-info' +const noopHeadPath = require.resolve('next/dist/client/components/noop-head') + export default async function transformSource( this: any, source: string, @@ -24,5 +27,10 @@ export default async function transformSource( return callback(null, source, sourceMap) } + if (noopHeadPath === this.resourcePath) { + warnOnce( + `Warning: You're using \`next/head\` inside app directory, please migrate to \`head.js\`. Checkout https://beta.nextjs.org/docs/api-reference/file-conventions/head for details.` + ) + } return callback(null, source, sourceMap) } diff --git a/packages/next/client/components/noop-head.tsx b/packages/next/client/components/noop-head.tsx index 42fbdb94f230f03..ff4419f83520d25 100644 --- a/packages/next/client/components/noop-head.tsx +++ b/packages/next/client/components/noop-head.tsx @@ -1,11 +1,3 @@ -import { warnOnce } from '../../shared/lib/utils/warn-once' - -if (process.env.NODE_ENV !== 'production') { - warnOnce( - `You're using \`next/head\` inside app directory, please migrate to \`head.js\`. Checkout https://beta.nextjs.org/docs/api-reference/file-conventions/head for details.` - ) -} - export default function NoopHead() { return null } diff --git a/test/e2e/app-dir/head/head.test.ts b/test/e2e/app-dir/head/head.test.ts index 0dc7af80755ae83..f546541b1169b69 100644 --- a/test/e2e/app-dir/head/head.test.ts +++ b/test/e2e/app-dir/head/head.test.ts @@ -102,12 +102,12 @@ createNextDescribe( if (globalThis.isNextDev) { expect( - errors.some( + errors.filter( (output) => output === - `You're using \`next/head\` inside app directory, please migrate to \`head.js\`. Checkout https://beta.nextjs.org/docs/api-reference/file-conventions/head for details.\n` - ) - ).toBe(true) + `Warning: You're using \`next/head\` inside app directory, please migrate to \`head.js\`. Checkout https://beta.nextjs.org/docs/api-reference/file-conventions/head for details.\n` + ).length + ).toBe(1) const dynamicChunkPath = path.join( next.testDir,