Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sitemap via SRR not working on zeit now #106

Closed
miteyema opened this issue Feb 24, 2020 · 10 comments
Closed

sitemap via SRR not working on zeit now #106

miteyema opened this issue Feb 24, 2020 · 10 comments

Comments

@miteyema
Copy link
Contributor

miteyema commented Feb 24, 2020

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)
This bug report is available on Nuxt community (#c82)
@ghost ghost added the cmty:bug-report label Feb 24, 2020
@NicoPennec
Copy link
Member

@miteyema thanks for your very complete report 👍

I will investigate the root cause.

(issue linked to #95)

@NicoPennec
Copy link
Member

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

@miteyema
Copy link
Contributor Author

miteyema commented Feb 25, 2020

@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

@JackMarksThomas
Copy link

JackMarksThomas commented Feb 25, 2020

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?

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)```

@NicoPennec
Copy link
Member

@miteyema I found the issue with Now and the sitemap-module.

This is due to the @nuxtjs/now-builder that doesn't copy the sitemap-routes.json file generated on nuxt build by the sitemap-module.

To fix your deploy, update your now.json configuration with the "serverFiles" option setted as follows:

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

@miteyema
Copy link
Contributor Author

@NicoPennec Thank you so much for having a look at it and then solving it. Great work!

@heyjordn
Copy link

I've been searching for this solution for hours, thanks @NicoPennec

@NicoPennec
Copy link
Member

It seems a common use case, so I will add a FAQ section to the README file.

@Youhan
Copy link

Youhan commented Mar 14, 2021

Looks like the FAQ is somehow removed. I couldn't find this in the docs

@teleyinex
Copy link

This is not mentioned on the docs, so it would be nice. The fix proposed by @NicoPennec works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants