Nuxt/sitemap - error in production, doesn't work

awronski
351
awronski
commented 3 years ago

Hi!

  sitemap: {
    path: '/sitemap.xml',
    hostname: 'https://example.com',
    routes () {
      return Promise.resolve(['one', 'two', 'three'])
        .then(res => res.map(user =>  '/users/' + user))
    }
  },

It works in dev mode, but it doesn't work in production mode (npm run build, npm run start).

I cannot access the sitemap, there is just timeout and This site can’t be reached
Nothing in the logs.

@NicoPennec Could you check it?

bug
0
awronski
351
awronski
commented 3 years ago

Problem is in the cache.
https://github.com/nuxt-community/modules/blob/master/modules/sitemap/index.js#L41

When I disable it everything works. Disabling:

  this.addServerMiddleware({
    path: options.path,
    handler (req, res, next) {
      // cache.get('routes')
      promisifyRoute(options.routes)

Not sure why

0
pi0
39.6k
pi0
commented 3 years ago

Hi. Thanks for report. I've found the bug, but not sure about workaround. Problem is that during generate or dev (which call to build) extendRoutes is being called so staticRoutes are available. For prod, we may need to somehow store result and just load it from .nuxt/dist.

0
NicoPennec
1.9k
NicoPennec
commented 3 years ago

Correct, the issue come from the staticRoutesPromise, in prod mode only.

I prepared a fix since yesterday ;-)
I will create a PR in few hours

2
pi0
39.6k
pi0
commented 3 years ago

@NicoPennec Haha so fast, I was doing the same, so waiting for PR. Thanks

0
awronski
351
awronski
commented 3 years ago

@pi0 Thanks for the explanation. One more question, why the extendRoutes is not called in production only?

0
pi0
39.6k
pi0
commented 3 years ago

Because builder is not available and routes should already being generated during build phase :)

1
NicoPennec
1.9k
NicoPennec
commented 3 years ago

@awronski your issue should be fixed on the latest release of nuxtjs/sitemap (v0.0.2)

0
t0ker
0
t0ker
commented 3 years ago

I cant get the module to run in production either, just receiving a 404 on /sitemap.xml

any idea if I might missing anything?

0
NicoPennec
1.9k
NicoPennec
commented 3 years ago

@t0ker, please share some details to reproduce: node.js version, nuxt version, module sitemap version, nuxt.config.js, nuxt build logs, etc.

0
alidcastano
1.7k
alidcastano
commented 3 years ago

@t0ker @NicoPennec I ran into this issue as well trying to create a sitemap example using nuxtent.

Here's a reproduction: https://github.com/nuxt-community/nuxtent-module/tree/master/examples/sitemap

0
Informations
Bug ReportOpen
#c49 - Created 3 years ago