diff --git a/packages/next-swc/crates/core/src/react_server_components.rs b/packages/next-swc/crates/core/src/react_server_components.rs index c77999cf93..8adecb9ea3 100644 --- a/packages/next-swc/crates/core/src/react_server_components.rs +++ b/packages/next-swc/crates/core/src/react_server_components.rs @@ -470,8 +470,11 @@ impl ReactServerComponents { handler .struct_span_err( span, - format!("NEXT_RSC_ERR_INVALID_API: {}", invalid_export_name) - .as_str(), + format!( + "NEXT_RSC_ERR_CLIENT_METADATA_EXPORT: {}", + invalid_export_name + ) + .as_str(), ) .emit() }) diff --git a/packages/next/src/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts b/packages/next/src/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts index e89971d689..8b2c52e85c 100644 --- a/packages/next/src/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts +++ b/packages/next/src/build/webpack/plugins/wellknown-errors-plugin/parseRSC.ts @@ -16,6 +16,8 @@ function formatRSCErrorMessage( const NEXT_RSC_ERR_REACT_API = /.+NEXT_RSC_ERR_REACT_API: (.*?)\n/s const NEXT_RSC_ERR_SERVER_IMPORT = /.+NEXT_RSC_ERR_SERVER_IMPORT: (.*?)\n/s const NEXT_RSC_ERR_CLIENT_IMPORT = /.+NEXT_RSC_ERR_CLIENT_IMPORT: (.*?)\n/s + const NEXT_RSC_ERR_CLIENT_METADATA_EXPORT = + /.+NEXT_RSC_ERR_CLIENT_METADATA_EXPORT: (.*?)\n/s const NEXT_RSC_ERR_CLIENT_DIRECTIVE = /.+NEXT_RSC_ERR_CLIENT_DIRECTIVE\n/s const NEXT_RSC_ERR_CLIENT_DIRECTIVE_PAREN = /.+NEXT_RSC_ERR_CLIENT_DIRECTIVE_PAREN\n/s @@ -93,6 +95,13 @@ function formatRSCErrorMessage( `\n\n${fileName} must be a Client Component. Add the "use client" directive the top of the file to resolve this issue.\n\n` ) formattedVerboseMessage = '\n\nImport path:\n' + } else if (NEXT_RSC_ERR_CLIENT_METADATA_EXPORT.test(message)) { + formattedMessage = message.replace( + NEXT_RSC_ERR_CLIENT_METADATA_EXPORT, + `\n\nYou are attempting to export "$1" from a component marked with "use client", which is disallowed. Either remove the export, or the "use client" directive. Read more: https://beta.nextjs.org/docs/api-reference/metadata\n\n` + ) + + formattedVerboseMessage = '\n\nFile path:\n' } return [formattedMessage, formattedVerboseMessage] diff --git a/test/development/acceptance-app/rsc-build-errors.test.ts b/test/development/acceptance-app/rsc-build-errors.test.ts index cefca0802e..affd3e3ac6 100644 --- a/test/development/acceptance-app/rsc-build-errors.test.ts +++ b/test/development/acceptance-app/rsc-build-errors.test.ts @@ -55,7 +55,7 @@ createNextDescribe( await session.patch(pageFile, uncomment) expect(await session.hasRedbox(true)).toBe(true) expect(await session.getRedboxSource()).toInclude( - '"metadata" is not supported in app/' + 'You are attempting to export "metadata" from a component marked with "use client", which is disallowed.' ) // Restore file @@ -70,7 +70,7 @@ createNextDescribe( await session.patch(pageFile, uncomment) expect(await session.hasRedbox(true)).toBe(true) expect(await session.getRedboxSource()).toInclude( - '"generateMetadata" is not supported in app/' + 'You are attempting to export "generateMetadata" from a component marked with "use client", which is disallowed.' ) await cleanup()