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

Build fail when using React.cache in sitemap.ts #55561

Closed
1 task done
mwskwong opened this issue Sep 19, 2023 · 3 comments · Fixed by #55579
Closed
1 task done

Build fail when using React.cache in sitemap.ts #55561

mwskwong opened this issue Sep 19, 2023 · 3 comments · Fixed by #55579
Assignees
Labels
linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@mwskwong
Copy link

mwskwong commented Sep 19, 2023

Link to the code that reproduces this issue

https://github.com/mwskwong/cache-in-sitemap

To Reproduce

  1. Call a function, e.g. fetcher, wrapped in React.cache in sitemap.ts
  2. Attempt to build the project

Current vs. Expected behavior

Current: the following error will appear during build

   Collecting page data ..TypeError: (0 , p.cache) is not a function
    at 5398 (\.next\server\app\sitemap.xml\route.js:1:605)
    at t (\.next\server\webpack-runtime.js:1:127)
    at a (\.next\server\app\sitemap.xml\route.js:1:1737)
    at \.next\server\app\sitemap.xml\route.js:1:1764
    at t.X (\.next\server\webpack-runtime.js:1:1191)
    at \.next\server\app\sitemap.xml\route.js:1:1750
    at Object.<anonymous> (\.next\server\app\sitemap.xml\route.js:1:1791)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)

> Build error occurred
Error: Failed to collect page data for /sitemap.xml
    at \node_modules\next\dist\build\utils.js:1191:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}

Expected: build should be successful

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 Home
    Binaries:
      Node: 18.17.1
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.20-canary.40
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.3
    Next.js Config:
      output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Additional context

No response

NEXT-1635

@mwskwong mwskwong added the bug Issue was opened via the bug report template. label Sep 19, 2023
@balazsorban44
Copy link
Member

This is expected. The sitemap.xml is not a React Server Component, so react is not necessary.

Next.js will already cache the fetch call, which you can configure as described in https://nextjs.org/docs/app/api-reference/functions/fetch#optionscache if necessary.

@huozhi huozhi reopened this Sep 19, 2023
@huozhi huozhi added area: API routes linear: next Confirmed issue that is tracked by the Next.js team. and removed bug Issue was opened via the bug report template. labels Sep 19, 2023
@huozhi huozhi self-assigned this Sep 19, 2023
feedthejim pushed a commit that referenced this issue Sep 19, 2023
`isAppLayer` condition was missing `app-metadata-route` layer, made it
as a util now like other webpack layer utils, add metadata route layer
to the group. Then `React.cache` can be available there.

Also update regex to be compatible across platform

Fixes #55561 
Closes NEXT-1635
@huozhi
Copy link
Member

huozhi commented Sep 19, 2023

We patched a fix in next 13.5 that this API is available now for sitemap.js, but it's same like react server components, only the APIs available in react server components are available here. Thanks. So if it's in some util and being imported to the sitemap, these APIs should still be available

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. 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 added the locked label Oct 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.

3 participants