Next.js Discord

Discord Forum

Robots.txt turn into serverless function

Unanswered
Picardy Spaniel posted this in #help-forum
Open in Discord
Picardy SpanielOP
Hi,
I am generating robots.txt and sitemap.xml files via the next-sitemap package, I am also using next-i18 for internationalization. Now for some reason, the sitemap and robots.txt files are copied over to the locale build folders and they turn into serverless function. Furthermore, they have different content.

Could someone please help me out on how do I resolve this issue ?

4 Replies

It’s expected, Next.js have to turn it into a serverless function in order to generate it on runtime.

And what do you mean by they have different content?
Picardy SpanielOP
so, the robots.txt on the root has the desired content (ref. 1st photo)

and the robots.txt inside the locales folder has different content (ref. 2nd photo)

Since, /en/robots.txt is served by default, thus the robots.txt on the root is not being served
Picardy SpanielOP
also, the robots.txt should be made at build time and not on the run time, isn't it so ?
I thought you are using server side sitemap generation

Can you provide your configuration or the function to generate sitemap?

And about your robots txt, it shouldn’t located in a subdirectory, it’s likely a problem in your configuration