[SOLVED] Failed to parse URL from sitemap.xml at node:internal/deps/undici/undici....
Hi,
Every build (dev and prod) shows this (non-blocking) error:
Here’s my current Nitro configuration:
And my Nuxt sitemap configuration:
The /api/sitemap handler currently returns an empty array for testing:
Even when I return valid URLs, the error still appears. Have you encountered this issue? Any advice would be appreciated! Thanks and regards, Davide
Even when I return valid URLs, the error still appears. Have you encountered this issue? Any advice would be appreciated! Thanks and regards, Davide
13 Replies
Hi @Davide Marchet. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The error message “Failed to parse URL from sitemap.xml” during your Nuxt build is likely related to how the sitemap is being generated or consumed during the prerendering process. Based on your configuration and the knowledge sources, here are some key points and suggestions:
1. sitemap.xml in prerender routes
You have included
The sitemap must contain valid, absolute URLs. If your
According to the Nuxt prerendering documentation, you can specify routes to prerender, and you can also use the crawler to discover linked pages. If a route like
See: Nuxt Prerendering Docs 4. Sitemap Module and Dynamic URLs
If you are using dynamic URLs in your sitemap, you need to provide an API source that returns all the URLs you want included. The sitemap module expects these to be valid and absolute.
See: nuxt-sitemap dynamic URLs guide (as referenced in this answer) 5. Non-blocking Error
Since you mentioned the error is non-blocking, it means the build continues, but the sitemap or some prerendered routes may not be generated as expected. What you can do: - Ensure your
The error is most likely caused by the sitemap route returning invalid or empty data, or by the use of relative URLs. Make sure your sitemap returns valid, absolute URLs and that your configuration matches your deployment needs. If the error persists even with valid URLs, it may be a bug or edge case in the sitemap or prerendering process, but the knowledge sources do not provide further details on this specific scenario. If you need to ignore the error for now, setting
You have included
"sitemap.xml"
in your nitro.prerender.routes
array. This instructs Nitro to prerender the /sitemap.xml
route, which is correct if you want a static sitemap file generated. However, if the route is not returning a valid sitemap or the URLs inside are not absolute (i.e., missing protocol and domain), the Nitro crawler (which uses undici
for fetch requests) may fail to parse them, resulting in the error you see.
2. Absolute URLs RequiredThe sitemap must contain valid, absolute URLs. If your
/api/sitemap
handler (used as a source for the sitemap) returns an empty array or relative URLs, this can cause parsing errors. Make sure that when you do return URLs, they are fully qualified (e.g., <https://example.com/page
>), not just /page
or empty.
3. Prerendering and Sitemap GenerationAccording to the Nuxt prerendering documentation, you can specify routes to prerender, and you can also use the crawler to discover linked pages. If a route like
/sitemap.xml
is included but does not return a valid sitemap, or if the sitemap module tries to fetch and parse it but encounters invalid data, you may see this error.See: Nuxt Prerendering Docs 4. Sitemap Module and Dynamic URLs
If you are using dynamic URLs in your sitemap, you need to provide an API source that returns all the URLs you want included. The sitemap module expects these to be valid and absolute.
See: nuxt-sitemap dynamic URLs guide (as referenced in this answer) 5. Non-blocking Error
Since you mentioned the error is non-blocking, it means the build continues, but the sitemap or some prerendered routes may not be generated as expected. What you can do: - Ensure your
/api/sitemap
returns an array of absolute URLs when not empty.
- Double-check that your siteUrl
(or SITE_URL
env variable) is set correctly and is a valid URL.
- If you do not need to prerender /sitemap.xml
, you can remove it from the prerender.routes
array to avoid the error.
- If you want to prerender it, make sure the route returns a valid XML sitemap with absolute URLs.
Summary:The error is most likely caused by the sitemap route returning invalid or empty data, or by the use of relative URLs. Make sure your sitemap returns valid, absolute URLs and that your configuration matches your deployment needs. If the error persists even with valid URLs, it may be a bug or edge case in the sitemap or prerendering process, but the knowledge sources do not provide further details on this specific scenario. If you need to ignore the error for now, setting
failOnError: false
(as you have) is appropriate, but for a clean build, ensure your sitemap and URLs are valid and absolute.
If you need more details on dynamic URLs in sitemaps, see the nuxt-sitemap dynamic URLs guide as referenced in the knowledge sources.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@651060307145392139> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai it's ok I dont' prerender sitemap.xml despite I've got dynamic routes?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Yes, it is technically okay not to prerender routes, even if you have dynamic routes. In Nuxt, prerendering is optional and mainly used to improve performance and SEO by generating static HTML for specific routes at build time. If you choose not to prerender dynamic routes, those pages will be rendered on-demand at runtime (if you are using SSR or a server/edge preset), or they may not be available at all if you deploy to static hosting without prerendering them.
If you are using static hosting and do not prerender your dynamic routes, those routes will not exist as static files and will result in 404 errors unless you handle them on the client side (e.g., as a single-page app with
- If you do not prerender dynamic routes and use static hosting, those routes will not be available unless handled client-side. - If you use SSR or a server/edge preset, dynamic routes will be rendered at runtime. - Prerendering is recommended for SEO and performance, but not strictly required. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
ssr: false
) or use fallback pages like 200.html
and 404.html
as described in the documentation. In this case, you might only need a single index.html
file, plus 200.html
and 404.html
fallbacks, which you can configure your static host to serve for all requests. This approach is suitable for purely client-side rendered apps, but you will lose the SEO and performance benefits of prerendering dynamic routes Universal Rendering.
If you want your dynamic routes to be available as static files, you need to explicitly add them to the prerender configuration, since the crawler cannot discover dynamic routes unless they are linked from other pages or specified manually Prerendering.
In summary:- If you do not prerender dynamic routes and use static hosting, those routes will not be available unless handled client-side. - If you use SSR or a server/edge preset, dynamic routes will be rendered at runtime. - Prerendering is recommended for SEO and performance, but not strictly required. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@651060307145392139> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai sorry I did a mistake. My question was:
it's ok if I dont' prerender sitemap.xml despite I've got dynamic routes
Let me check the knowledge base for you again. One moment! :books:
----------------------
Yes, it is okay if you don't prerender
sitemap.xml
even when you have dynamic routes. Prerendering sitemap.xml
is not required for your application to function or for dynamic routes to work. The sitemap is typically generated dynamically (for example, via an API route like /api/sitemap
) and consumed by search engines to discover your site's URLs.
The knowledge sources indicate that you can include sitemap.xml
in the prerender routes if you want a static version, but it's not mandatory. If your sitemap is generated dynamically and you don't need a static file, you can simply omit it from the prerender.routes
array in your configuration Prerendering.
Just ensure that your sitemap (whether static or dynamic) returns valid, absolute URLs, especially if it's being accessed by search engines or other tools. Not prerendering sitemap.xml
will not affect the availability of your dynamic routes, as long as those routes are handled correctly in your application.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@651060307145392139> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
can you verify which version you're using
and just to confirm, this is only thrown when you add the module?
can i suggest doing
/sitemap.xml
Hi @harlan !
I use "@nuxtjs/sitemap": "^5.3.5" and it happens inly when I add sitemap into nitro route config:
If I remove it from routes the errore gone.
Thanks and regards,
Davide
Ye I think it's because you're missing the /
Hi @harlan thanks! Do you mean /sitemap.xml?
@harlan thanks! It works!
cool, yeh ideally Nitro would be able to recover from missing leading slashes