vercel-builder: Sitemap is not available with nuxt/sitemap & nuxt/i18n module

I’m struggling making the sitemaps work with having the nuxt/sitemap and i18n module enabled.

This is my i18n configuration:

export default {
    locales: supportedLanguages,
    defaultLocale: 'ch-de',
    strategy: 'prefix',
    seo: false,
    lazy: true,
    langDir: 'lang/',
    parsePages: false,
    pages: computedRoutes,
    vueI18n: {
        fallbackLocale: 'ch-de'
    },
    detectBrowserLanguage: {
        useCookie: true,
        cookieKey: 'i18n_redirected',
        alwaysRedirect: false,
        fallbackLocale: 'ch-de',
        onlyOnRoot: true
    }
}

and here is my sitemap config fron the nuxt.config.js:

sitemap: {
    hostname: 'https://someurl.com',
    exclude: ['/**'],
     sitemaps: [
        {
            path: '/sitemap.xml',
            exclude: ['/**'],
            routes() {
                return getRoutesFor('keypersons')
            },
            gzip: false
        }
    ]
}

what i found out is that the generated sitemap-routes.json is not included when deploying with this builder… so i added the file to the serverFilesarray in my vercel.json.

"serverFiles": [
          "lang/**",
          "config/**",
          "sitemap/**",
          ".nuxt/dist/sitemap-routes.json"
]

With my sitemap configuration i assume that the sitemap.xml would be under https://someurl.com/sitemap.xml but i first get redirected to someurl.com/ch-de/sitemap.xml and than i get a 404 on that page.

I also tried to adjust things in the i18n config but i just can’t make it work. I have to use the i18n prefix strategy because i want all urls to be prefixed with the language.

Locally when i start nuxt in server mode everything works fine.

Did someone have the same Issue? or is thins a known problem?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

@andrew-boyd Your solution works for me! I had async routes() function in my configuration. I wrapped everything in export default async function and now it works like a charm! Thank you.

I’m also getting a 404 on a project rather than a successful sitemap.xml. I’m going to see if I can get a working reproduction for you.

Same here, without i18n. My vercel.json:

{
  "version": 2,
  "builds": [
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {
        "generateStaticRoutes": false,
        "serverFiles": ["serverMiddleware/**", "./.nuxt/dist/sitemap-routes.json"]
      }
    }
  ]
}

This is how vercel sees the source: image

Any help would be appreciated.

@danielroe I converted my nuxt.config.js back to a regular object export instead of an async function that returned a config object - and moved all my previously inline async work to a custom module - and I’m back in business. Just following up to confirm that for my case it was 100% an issue with the async config option of Nuxt.

@andrew-boyd Great - perfect!

By the way, I would recommend moving async parts of your configuration into a module(s) in any case, if possible.

@danielroe So I put together a minimal case - clean install of nuxt and the @nuxtjs/sitemap package along with using the vercel builder and… it works just fine. 😅

https://github.com/wearebraid/nuxt-vercel-builder-sitemap-example https://nuxt-sitemap-vercel-404-8on3s02u1.vercel.app/

No 404 errors in sight. There must be some common-thread others and I are hitting in more complex setups so I’m going to work to recreate my project’s complexity on a feature branch in this repo and I’ll report back if I come up with a solve that may be useful for the whole class.