sitemap via SRR not working on zeit now

miteyema
0
miteyema
commented 2 months ago

Version

2.0.1

Reproduction link

https://github.com/miteyema/nuxt-sitemap-now

Steps to reproduce

  • I have an api serverless function to return the dynamic routes so I can build a complete sitemap
  • The dynamic routes are added to nuxt generate, so they are available for the sitemap module
  • SRR app works in dev mode, but once deployed with zeit now in production (using nuxt/now-builder), it's not working
  • If I use nuxt generate (to make a static app), sitemap does work

This is the config object for sitemap in nuxt.config.js:

 sitemap: {
    hostname: baseURL,
    defaults: {
      lastmod: new Date(),
      changefreq: 'weekly',
      priority: 0.8
    }
}

The generate part in nuxt.config.js:

generate: {
    async routes() {
      const response = await axios.get('routes', {
        // FYI: generate will always be in production mode
        baseURL: apiBaseURL
      })
      const dynamicRoutes = response.data
      return dynamicRoutes
    }
}

What is expected ?

sitemap.xml is shown

What is actually happening?

"Nuxt.js Internal Server Error" is show with status code 500.
The following log is shown on the server:

ERROR  Cannot read property 'filter' of null
  at node_modules/@nuxtjs/sitemap/lib/routes.js:14:21
  at Array.forEach (<anonymous>)
  at excludeRoutes (node_modules/@nuxtjs/sitemap/lib/routes.js:11:12)
  at Object.cache.staticRoutes (node_modules/@nuxtjs/sitemap/lib/middleware.js:48:30)
  at AsyncCache.load [as _load] (node_modules/@nuxtjs/sitemap/lib/cache.js:19:68)
  at processTicksAndRejections (internal/process/task_queues.js:94:5)
bug
0
NicoPennec
1.7k
NicoPennec
commented 2 months ago

@miteyema thanks for your very complete report ๐Ÿ‘

I will investigate the root cause.

(issue linked to https://github.com/nuxt-community/sitemap-module/pull/95)

0
NicoPennec
1.7k
NicoPennec
commented 2 months ago

@miteyema which version on this following doc, do you use to deploy?
https://nuxtjs.org/faq/now-deployment/
v2 or v1?

0
miteyema
0
miteyema
commented 2 months ago

@NicoPennec That would be v2. I have made a repo (configured with now) with nuxt and only your sitemap module and I still have the same error:

Repo: https://github.com/miteyema/nuxt-sitemap-now
URL: https://nuxt-sitemap.now.sh/sitemap.xml

0
JackMarksThomas
0
JackMarksThomas
commented 2 months ago

I'm having a very similar issue where it's working locally however when it's in a live environment I am also getting Zeit Now internal server error. Though our sitemap module config is slightly different:

/**
** Sitemap module
*/
sitemap: {
    // routes: async () => {
    //   const routes = await getRoutes()
    //   return routes
    // },
    // Still does not work if I hardcode the routes
    routes: ['/', 'journal', '/journal/overview', '/journal/medical', '/journal/wellness', '/locations'],
    hostname: baseUrl,
    path: '/sitemap.xml',
    gzip: true,
    generate: false,
}

I believe this has been an issue for a few weeks since I first looked at the Sitemap, but have been working on other stuff since. May have to create my own sitemap.xml with a serverless function as we're going to be launching on Thursday

What is actually happening?

[GET] /sitemap.xml 13:02:42:32 ERROR Cannot read property 'map' of null at joinRoutes (node_modules/@nuxtjs/sitemap/lib/cache.js:76:31) at AsyncCache.load [as _load] (node_modules/@nuxtjs/sitemap/lib/cache.js:19:18) (repeated 1 times) ERROR Cannot read property 'map' of null at joinRoutes (node_modules/@nuxtjs/sitemap/lib/cache.js:76:31) at AsyncCache.load [as _load] (node_modules/@nuxtjs/sitemap/lib/cache.js:19:18)

0
Informations
Bug Report โ€ข Open
#c82 - Created 2 months ago