sitemap-module icon indicating copy to clipboard operation
sitemap-module copied to clipboard

404 error in production, working fine in dev (Nuxt 3)

Open skrypt-nl opened this issue 3 years ago • 13 comments
trafficstars

First let me say that I've checked out several other issues already, but none of the following solutions posted over there works. Some of this things I tried / made sure:

  • @nuxt/sitemap is in dependencies
  • Changed export default defineNuxtConfig( { ... } ) to module.exports = { ... } in nuxt.config.ts

As stated in the title, /sitemap.xml is working perfectly fine in dev mode (npm run dev). However, when building the site (npm run build) and starting it (nuxi preview), the site returns my 404 page. The /sitemap_style.xsl file is available in production mode. It happens both on my local device as well as on my production server (NGINX reverse proxy). My thoughts are that this is a bug with Nuxt 3, but I cannot say this with 100% certainty.

This is my nuxt.config.ts sitemap object:

sitemap: {
    xslUrl: '/sitemap_style.xsl',
    routes: async () => {
        const { data } = await axios.get('https://api.example.com') // this is the actual URL in my code, which is working
        let routes = []
        data.data.forEach((page) => {
            let route = { url: page.slug, lastmod: page.date_updated }

            routes.push(route)
        })
        return routes
    }
}

skrypt-nl avatar Dec 30 '21 13:12 skrypt-nl

bump, has there been any updates here? Our company is starting a fresh project on Nuxt 3 and have the capacity to help work on a Nuxt 3 build if there are any tasks that need to be completed

HelloAlexPan avatar Jan 03 '22 02:01 HelloAlexPan

@HelloAlexPan no update on the issue yet unfortunately, but I downgraded my project back to Nuxt 2. Version 3 feels a little too instable and has too many small issues for a production ready site in my eyes.

skrypt-nl avatar Jan 03 '22 07:01 skrypt-nl

If anyone find a fix to this bug I would be really interested ! Hope we will be able to use Sitemap Module with Nuxt 3 soon.

desaintflorent avatar Jan 09 '22 13:01 desaintflorent

@NicoPennec @Atinux I'd like to apply as maintainer for this repo too. Any chance for that to happen?

dargmuesli avatar Feb 02 '22 09:02 dargmuesli

Sitemap integration with Nuxt3/Nitro needs some additional hooks to generate support that is not stable yet until we can move to use nitro pack (https://github.com/nuxt/framework/discussions/1690)

Thanks for your interest @HelloAlexPan @desaintflorent @dargmuesli to maintain repo 💚

I will try to contact the module author (@NicoPennec) to see how we can work together and support Nuxt3.

pi0 avatar Feb 02 '22 11:02 pi0

Also experiencing this problem in this project: https://github.com/enterspeedhq/enterspeed-demo-nuxt3 Works great in dev, but throws a 404 in production: https://enterspeed-demo-nuxt3.netlify.app/sitemap.xml

Would be awesome to have this fixed! 😊

Bjornnyborg avatar Feb 11 '22 07:02 Bjornnyborg

Any energy to make a PR to fix it @Bjornnyborg ?

atinux avatar Feb 14 '22 16:02 atinux

@Atinux Thanks for the suggestion, but i don't think i have the insights and skills necessary to make this happen. 🤔

Bjornnyborg avatar Feb 15 '22 08:02 Bjornnyborg

I'm not quite sure what "some additional hooks to generate support" and "until we can move to use nitro pack" mean specifically. Is something like https://github.com/nuxt-community/robots-module/pull/52 required or is there a feature to be waited for in nuxt framework? @pi0

dargmuesli avatar Feb 15 '22 18:02 dargmuesli

Since it works in develop, i would guess that the problem is something to do with not using the proper hook in nuxt3 production?

In my project i have dynamic routing controlled by Enterspeed, so i was able to just make a simple script (triggered by a build:before hook) that fetches my routes from the API and using the sitemap.js module write a sitemap.xml to the public folder.

Bjornnyborg avatar Feb 17 '22 07:02 Bjornnyborg

tmp fix: save the file in public/ and it works :')

Fy- avatar Apr 10 '22 23:04 Fy-

is there anyone find a way to fix this bug ?

Ahmedelforjani avatar Jun 13 '22 20:06 Ahmedelforjani

https://github.com/nuxt-community/sitemap-module/issues/248#issuecomment-1169105131

d3xter-dev avatar Jun 29 '22 17:06 d3xter-dev