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

Error when using robots.txt and sitemap.xml as route handlers in appDir #45947

Closed
1 task done
Fredkiss3 opened this issue Feb 15, 2023 · 3 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@Fredkiss3
Copy link
Contributor

Fredkiss3 commented Feb 15, 2023

Verify canary release

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

Provide environment information

Operating System:
Platform: linux
Arch: x64
Version: Ubuntu 20.04.0 LTS Wed Feb 15 2023 15:52:38 GMT+0100 (Central European Standard Time)
Binaries:
Node: 16.14.2
npm: 7.17.0
Yarn: 1.22.19
pnpm: 7.13.6
Relevant packages:
next: 13.1.7-canary.15
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0

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

App directory (appDir: true), Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://stackblitz.com/edit/github-t3cgzq

To Reproduce

Run the project, then click on one of links. When returning back you'll be met with an unknown error
You could also move the folders robots.txt and sitemap.xml and run the next build It will give this error :

TypeError: Cannot read properties of undefined (reading '')
TypeError: Cannot read properties of undefined (reading '')
    at Va (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1205:56)
    at Ma (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1335:50)
    at Array.toJSON (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1066:32)
    at stringify ()
    at Ua (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1393:53)
    at Qa (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1185:35)
    at ping (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1194:32)
TypeError: Cannot read properties of undefined (reading '')
    at Va (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1205:56)
    at Ma (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1335:50)
    at Object.toJSON (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1066:32)
    at stringify ()
    at Ua (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1393:53)
    at Qa (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1185:35)
    at ping (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1194:32)
TypeError: Cannot read properties of undefined (reading '')
    at Va (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1205:56)
    at Ma (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1335:50)
    at Array.toJSON (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1066:32)
    at stringify ()
    at Ua (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1393:53)
    at Qa (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1185:35)
    at ping (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1194:32)
TypeError: Cannot read properties of undefined (reading '')
    at Va (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1205:56)
    at Ma (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1335:50)
    at Array.toJSON (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1066:32)
    at stringify ()
    at Ua (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1393:53)
    at Qa (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1185:35)
    at ping (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1194:32)

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading '')
    at Va (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1205:56)
    at Ma (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1335:50)
    at Array.toJSON (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1066:32)
    at stringify ()
    at Ua (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1393:53)
    at Qa (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1185:35)
    at ping (file:///home/projects/github-t3cgzq/.next/server/chunks/869.js:1194:32)

Describe the Bug

When using robots.txt/route.ts or sitemap.xml/route.ts next give an error in dev and in build.

One weird thing is that if we move these files into (goup)/robots.txt/route.ts and (goup)/sitemap.xml/route.ts, in dev it will give us an error but on prod, it will work fine.

It seems like there is a conflict between the metadata generation and these routes.

Expected Behavior

next should not throw an error when using robots.txt or sitemap.xml as route handlers, if this is a legit error, then. maybe throw a more descriptive error.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@Fredkiss3 Fredkiss3 added the bug Issue was opened via the bug report template. label Feb 15, 2023
@karlhorky
Copy link
Contributor

This seems to be similar to the bug reported by @Josehower :

sdorra added a commit to sdorra/sdorra.dev that referenced this issue Feb 18, 2023
sdorra added a commit to sdorra/sdorra.dev that referenced this issue Feb 24, 2023
@Fredkiss3
Copy link
Contributor Author

It has been fixed in the latest canary 13.2.2-canary.2.

@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 Mar 30, 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.
Projects
None yet
Development

No branches or pull requests

2 participants