Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sitemap.ts marked as as "use client" in version 13.4.9 #52390

Closed
1 task done
Svish opened this issue Jul 7, 2023 · 5 comments · Fixed by #52403
Closed
1 task done

sitemap.ts marked as as "use client" in version 13.4.9 #52390

Svish opened this issue Jul 7, 2023 · 5 comments · Fixed by #52403
Assignees
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@Svish
Copy link

Svish commented Jul 7, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 20.1.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.8
      eslint-config-next: 13.4.9
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App Router

Link to the code that reproduces this issue or a replay of the bug

https://github.com/Svish/geekality.net/tree/e1a6cda84d9c3bd1879f405f96c616102fdeee8a

To Reproduce

  1. Run npm i next@13.4.9 (or .10-canary.0)
  2. Use import 'server-only' in a file that's imported by ./src/app/sitemap.ts.
  3. Run npm run build

Describe the Bug

I have a file that uses import 'server-only' to make sure it doesn't leak into client components. In version 13.4.8 this was working fine, but once I tried to update next to the current 13.4.9, I'm suddenly getting an error because of this. And the weirder part is that the error seem to be coming from my ./src/app/sitemap.ts, which is definitely not using any client components, it's actually not using any components at all. It's the metadata route for sitemaps from Next. 🤔

Here's the output from running npm run build on version 13.4.9. The latest canary produces the same error:

- warn You have enabled experimental feature (typedRoutes) in next.config.js.
- warn Experimental features are not covered by semver, and may cause unexpected or broken application behavior. 
Use at your own risk.

Warning: Contentlayer might not work as expected on Windows
Generated 269 documents in .contentlayer
Failed to compile.

./src\content\index.ts
ReactServerComponentsError:

You're importing a component that needs server-only. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.
Learn more: https://nextjs.org/docs/getting-started/react-essentials

   ╭─[D:\projects\geekality.net\src\content\index.ts:1:1]
 1 │ import 'server-only'
   · ────────────────────
 2 │
 3 │ import { byString, byStringValue } from '@/util/sort'
 4 │ import { onlyPublished } from './filters'
   ╰────

One of these is marked as a client entry with "use client":
  ./src\content\index.ts
  ./src\app\sitemap.ts
  ./src\app\sitemap.ts


> Build failed because of webpack errors
- info Creating an optimized production build .

Expected Behavior

The import 'server-only' in my ./src/content/index.ts shouldn't cause any issues in sitemap.ts, or any other files for that matter, just because I update next to version 13.4.9.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1417

@Svish Svish added the bug Issue was opened via the bug report template. label Jul 7, 2023
@Arctomachine
Copy link

Arctomachine commented Jul 7, 2023

It started happening at canary 2, so one of commits between 1 and 2 causes this.
v13.4.9-canary.1...v13.4.9-canary.2

@huozhi huozhi added the linear: next Confirmed issue that is tracked by the Next.js team. label Jul 7, 2023
@huozhi huozhi self-assigned this Jul 7, 2023
@timneutkens
Copy link
Member

Looking at the diff it's caused by this change: #51950

@kodiakhq kodiakhq bot closed this as completed in #52403 Jul 9, 2023
kodiakhq bot pushed a commit that referenced this issue Jul 9, 2023
After we separating the metadata routes to a separate layer, we didn't apply the webpack alias rules properly to it as it's should still be treated as pure "server" side

This PR fixes the aliasing for that new metadata layer and make it working properly with "server-only"

Fixes #52390
@franzwarning
Copy link

Seeing this same error with my icon.tsx file which is exporting a default async function which is getting headers from next/headers. I get the error:

You're importing a component that needs next/headers. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.

None of the parents are client components. It looks like the fix you pushed is only for those marked w/ server-only?

@huozhi
Copy link
Member

huozhi commented Jul 10, 2023

@franzwarning The fix is landed on latest canary, please upgrade to canary. The server-only marked it's works with server components hooks, so next/headers should work with that as well after the fix.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants