rsnext/packages/next
Kevin Wang b942a6f494
chore: improve error when exporting metadata from client component (#46334)
<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

This improves the ambiguous error seen when exporting `metadata` or
`generateMetadata` from a component marked with the `"use client";`
directive.

Example output from tests (`pnpm test-dev
test/development/acceptance-app/rsc-build-errors.test`)

```console
File path:
  app/client-with-errors/metadata-export/page.js
  console.log
    browser log: ./app/client-with-errors/metadata-export/page.js
    ReactServerComponentsError:
    
    You are attempting to export "generateMetadata" 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
    
       ,-[6:1]
     6 | 
     7 | // export const metadata = { title: 'client-metadata' }
     8 | 
     9 | export async function generateMetadata() { return { title: 'client-metadata' } }
       :                       ^^^^^^^^^^^^^^^^
       `----
    
    File path:
      app/client-with-errors/metadata-export/page.js
```

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-02-24 21:23:32 -08:00
..
compat next/compat/router (#42502) 2022-11-07 18:16:28 +00:00
font Add next/font import (#45891) 2023-02-16 15:33:39 +01:00
image-types
legacy BREAKING CHANGE: Rename next/image to next/legacy/image & rename next/future/image to next/image (#41399) 2022-10-14 01:59:22 +00:00
navigation-types next/navigation Typescript support for pages/ (#45919) 2023-02-14 17:26:01 -08:00
src chore: improve error when exporting metadata from client component (#46334) 2023-02-24 21:23:32 -08:00
types Update app-dir react bundle to leverage edge build (#46208) 2023-02-23 00:24:26 +01:00
amp.d.ts
amp.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
app.d.ts
app.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
babel.d.ts
babel.js
client.d.ts
client.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
config.d.ts
config.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
constants.d.ts
constants.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
document.d.ts
document.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
dynamic.d.ts
dynamic.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
error.d.ts
error.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
head.d.ts
head.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
headers.d.ts Add exports for new router (#41368) 2022-10-13 09:13:39 +00:00
headers.js Add exports for new router (#41368) 2022-10-13 09:13:39 +00:00
image.d.ts
image.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
index.d.ts typing: upgrade styled-jsx to remove workaround in build script (#39408) 2022-08-09 17:10:33 +00:00
jest.d.ts
jest.js
license.md Update license year (#44403) 2023-01-01 11:12:49 +01:00
link.d.ts
link.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
navigation.d.ts Add exports for new router (#41368) 2022-10-13 09:13:39 +00:00
navigation.js Add exports for new router (#41368) 2022-10-13 09:13:39 +00:00
package.json v13.2.2-canary.0 2023-02-24 16:58:01 -08:00
README.md docs(README): next.js logo with dark mode (#40223) 2022-09-13 16:39:52 +02:00
router.d.ts
router.js Alias all client, shared, pages dist assets for esm (#41034) 2022-09-29 21:24:04 +00:00
script.d.ts
script.js Alias next public api to esm on edge runtime (#42709) 2022-11-09 19:20:32 -08:00
server.d.ts Update @types/node to 14.14.31 (#41634) 2022-10-22 11:19:14 -07:00
server.js refactor: add named export in next/server (#39381) 2022-08-07 16:17:15 +00:00
taskfile-ncc.js Move core files to src folder and move JS files to TypeScript (#44405) 2023-01-03 10:05:50 +01:00
taskfile-swc.js Fix invalid sourcemaps in taskfile-swc (#45604) 2023-02-06 08:14:51 +00:00
taskfile-watch.js Replace taskr.watch for core compilation (#44027) 2022-12-14 16:06:53 +01:00
taskfile.js feat(cssnano-simple): merge into next repo (#46380) 2023-02-24 19:05:21 +01:00
tsconfig.json next/navigation Typescript support for pages/ (#45919) 2023-02-14 17:26:01 -08:00

Next.js

Getting Started

Visit https://nextjs.org/learn to get started with Next.js.

Documentation

Visit https://nextjs.org/docs to view the full documentation.

Who is using Next.js?

Next.js is used by the world's leading companies. Check out the Next.js Showcase to learn more.

Community

The Next.js community can be found on GitHub Discussions, where you can ask questions, voice ideas, and share your projects.

To chat with other community members you can join the Next.js Discord.

Our Code of Conduct applies to all Next.js community channels.

Contributing

Please see our contributing.md.

Good First Issues

We have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.

Authors

Security

If you believe you have found a security vulnerability in Next.js, we encourage you to responsibly disclose this and not open a public issue. We will investigate all legitimate reports. Email security@vercel.com to disclose any security vulnerabilities.

https://vercel.com/security