Open belei-bohdan opened 10 months ago
May I try it ?
I am also experiencing this as well. I've tried several combinations of generateStaticParams() to no avail.
because of here. I have to deep into this more, and get how to fix it. I'm a new, so I have more time
Curious if you were able to dig in any at all @JerryWu1234 - I haven't had the time, but this is pretty darn frustrating to say the least 😄
Curious if you were able to dig in any at all @JerryWu1234 - I haven't had the time, but this is pretty darn frustrating to say the least 😄
I'm digging in right now. because nextjs was big project. of course if you have any tips, it be well.
For now you can use app route for this
/** app/sitemap.xml/route.ts **/
// dynamically generate sitemap xml data
function getSitemap() {
const map = [
{
url: 'https://my.app.url',
lastModified: new Date(),
changeFrequency: 'daily',
priority: 1,
}
];
return `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
${map
.map(
(item) => `
<url>
<loc>${item.url}</loc>
<lastmod>${item.lastModified.toISOString()}</lastmod>
<changefreq>${item.changeFrequency}</changefreq>
<priority>${item.priority}</priority>
</url>
`,
)
.join('')}
</urlset>
`;
}
export async function GET() {
return new Response(getSitemap(), {
headers: {
'Content-Type': 'text/xml',
},
});
}
@sushantdhiman looks like workaround but seems to be working one ;)
But another question. Does it work in export mode ?
@modelga Yes, it will generate sitemap.xml
file in the out
folder
Looks like the issue affects dev server only. If a build is triggered it is still able to generate the sitemap.xml.
Same issue here, only affects the dev server (npm run dev
). Is there a plan to fix it?
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/generate-sitemap-with-output-export-h5v4vg
To Reproduce
Current vs. Expected behavior
Description:
Attempting to generate a sitemap using the provided example from the official Next.js documentation results in an error when the output is set to "export". The code functions correctly with output set to "standalone".
Code Used:
Next.js Configuration:
Current Behavior:
Accessing the "/sitemap.xml" endpoint results in a Server Error:
Expected Behavior:
Accessing "/sitemap.xml" should display the generated sitemap page without errors.
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Metadata (metadata, generateMetadata, next/head), Static HTML Export (output: "export")
Additional context
No response