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

[Probs a bug] Totally empty sitemap? Lol?

Open gustaveWPM opened this issue 2 years ago • 37 comments

Hello.

I'm using Next.js 13 with the App Router. I know that next-sitemap can generate good sitemaps files with this setup. I've already done this in my current (and first Next.js) project.

I'm doing my best with generateStaticParams, and have an exhaustive output of my paths when I build my Next project.

Output of yarn build:

Route (app)
┌ ● /[locale]
├   ├ /fr
├   └ /en
├ ● /[locale]/[categ]
├   ├ /fr/patch-notes
├   └ /en/patch-notes
├ ● /[locale]/[categ]/[subcateg]
├   ├ /fr/patch-notes/dashboard
├   ├ /fr/patch-notes/discord-bot
├   ├ /en/patch-notes/dashboard
├   └ /en/patch-notes/discord-bot
├ ● /[locale]/[categ]/[subcateg]/[slug]
├   ├ /fr/patch-notes/dashboard/post-01
├   ├ /en/patch-notes/dashboard/post-01
├   ├ /fr/patch-notes/discord-bot/post-01
├   └ /en/patch-notes/discord-bot/post-01
├ ● /[locale]/dashboard
├   ├ /fr/dashboard
├   └ /en/dashboard
├ ○ /apple-icon.png
├ ○ /favicon.ico
└ ○ /icon.svg

●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)

Here is sitemap.xml:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
</sitemapindex>

(yah, I'm crying)

Moreover, here's the disaster: As I'm a bit of an idiot (lol), I tend to use the git commit --amend command a lot and I totally lost the original code which was somehow "compatible" (?) with next-sitemap, and which was not generating empty sitemaps.

To be honest, I don't have the courage, nor the knowledge, to understand what's happening to take me from a correct sitemap generation to a totally empty one. ( :'( )

I've made a branch to help you to reproduce and investigate. https://github.com/Tirraa/dashboard_rtm/tree/next-sitemap-empty-sitemap-issue

:information_source: It would be also helpful to know how could I investigate myself? I naively assumed that if my routes were displayed correctly in the build output, it should be fine (lol).

Warm regards. ( I'm so sad to have an empty sitemap. :'( )

gustaveWPM avatar Sep 02 '23 07:09 gustaveWPM

Having the same issue, I thought it's my issue (missing some config) until I see this. Will wait for the inputs here.

RaenonX avatar Sep 03 '23 04:09 RaenonX

Up this, I have the same issue as well

yongyi520 avatar Sep 07 '23 11:09 yongyi520

Empty sitemap here as well

fgeorgsson avatar Sep 07 '23 18:09 fgeorgsson

For me it is just happening with the new app directory, I have 2 other projects with this same library and almost exactly the same configuration but they use the old pages directory and they work perfectly

letops avatar Sep 14 '23 04:09 letops

For me it is just happening with the new app directory, I have 2 other projects with this same library and almost exactly the same configuration but they use the old pages directory and they work perfectly

idk why, but it was initially working fine on my project, using the app directory. :/

gustaveWPM avatar Sep 17 '23 04:09 gustaveWPM

Empty sitemap as well

sofly avatar Sep 20 '23 11:09 sofly

When can we expect any comment or progress on this issue? We currently have to resort to maintaining the Sitemap manually which is quite cumbersome given that most of our pages are generated based on CMS content.

JJGoogles avatar Sep 20 '23 11:09 JJGoogles

Hmmm... I think I read somewhere that Next-Sitemap is based on the build-manifest.json file (.next/.build-manifest.json).

It seems that there is a lot more informations in the trace file (.next/trace) that in the build-manifest.json when the SSG from the App Directory's context is used.

Maybe Next-Sitemap was designed to work with Static generation, but not with the SSG one.

gustaveWPM avatar Sep 20 '23 23:09 gustaveWPM

ping @iamvishnusankar Have you started to investigate?

gustaveWPM avatar Sep 20 '23 23:09 gustaveWPM

Lol. I've done some changes in the architecture of my project, and now the sitemap generation came back.

Created a new branch, in addition of https://github.com/Tirraa/dashboard_rtm/tree/next-sitemap-empty-sitemap-issue

  • https://github.com/Tirraa/dashboard_rtm/tree/next-sitemap-empty-sitemap-issue2

Hope it would help to investigate.

gustaveWPM avatar Sep 22 '23 01:09 gustaveWPM

same issue here. Pages marked as Static during the build are in sitemap, but SSG not. ✅ ○ (Static) automatically rendered as static HTML (uses no initial props)● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)

rafalzawadzki avatar Sep 24 '23 14:09 rafalzawadzki

Idk why, but I have the impression that if you have a minimum of one "Server" page (nor SSG, nor Static), things go back to normal?

Could someone try creating a dynamic path [stupidworkaround] and putting in an empty page that just returns a div? Just to see.

If it works, you might as well create a dynamic path [notfound] and just put a 404 page into it, in a place where it's not a nuisance to do so.

gustaveWPM avatar Sep 24 '23 23:09 gustaveWPM

I have pages of all kinds in my build (two server side and two static) - still doesn't work.

rafalzawadzki avatar Sep 25 '23 04:09 rafalzawadzki

I have pages of all kinds in my build (two server side and two static) - still doesn't work.

Hmm, that's curious.

Does your next build feedback prints something like this?

λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps) ○ (Static) automatically rendered as static HTML (uses no initial props) ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)

gustaveWPM avatar Sep 28 '23 17:09 gustaveWPM

I have pages of all kinds in my build (two server side and two static) - still doesn't work.

Hmm, that's curious.

Does your next build feedback prints something like this?

λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)

○ (Static) automatically rendered as static HTML (uses no initial props)

● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)

Yup, with one more:


ℇ  (Streaming)  server-side renders with streaming (uses React 18 SSR streaming or Server Components)
λ  (Server)     server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)     automatically rendered as static HTML (uses no initial props)
●  (SSG)        automatically generated as static HTML + JSON (uses getStaticProps)

rafalzawadzki avatar Sep 29 '23 21:09 rafalzawadzki

I'm in the same boat, I've tried and tried but I can't get my sitemap to generate all the static paths, also on nextjs13

nsberrow avatar Oct 09 '23 10:10 nsberrow

Facing the same issue.

nitinTJ avatar Oct 26 '23 12:10 nitinTJ

I think it might be related to this issue : https://github.com/iamvishnusankar/next-sitemap/issues/692

bastienrobert avatar Oct 26 '23 12:10 bastienrobert

Could also be this: https://github.com/iamvishnusankar/next-sitemap/issues/700

rafalzawadzki avatar Nov 01 '23 13:11 rafalzawadzki

Same issue

erwannbst avatar Nov 23 '23 16:11 erwannbst

I had it working for some time without any issue. And today it decided to not work anymore as mentioned by everyone here. Trying to retrace what happened. My main changes have been to add trpc and clerk.

In case someone really stuck with it, I've migrate to the official, took me 20 minutes and its smooth.

agonist avatar Dec 06 '23 08:12 agonist

in my case it was related to this: https://github.com/iamvishnusankar/next-sitemap/issues/692

AlexanderBich avatar Dec 25 '23 12:12 AlexanderBich

I have one project having issues with sitemap on app router while others works fine, it was driving me crazy, I compared versions and downgraded to 4.1.8 and it seems to be working now. This library seems a little abandoned? The oficial sitemap support from nextjs is very basic, how do you even generate sitemaps for static pages generated at build time @agonist ?

evertjr avatar Jan 24 '24 06:01 evertjr

I have one project having issues with sitemap on app router while others works fine, it was driving me crazy, I compared versions and downgraded to 4.1.8 and it seems to be working now. This library seems a little abandoned? The oficial sitemap support from nextjs is very basic, how do you even generate sitemaps for static pages generated at build time @agonist ?

It depends on how you generate your static page, but on my side, I generate page based on data from my db, so I'm simply generating my sitemap based on the same data I use to generate static page. Just an example for the idea :

  const tools = await findAllToolsSlugOnly(); // this is my db call

  const allTools = tools.map((t) => {
    const to: R = {
      url: `${site}/ai-tools/${t.slug}`,
      lastModified: new Date(),
      changeFrequency: "daily",
      priority: 0.7,
    };
    return to;
  });

I'm doing something like that. So I have various array of from my static pages for different routes. once setup you don't have to touch it anymore and what's happening is very predictable which make the sitemap less mysterious and give you full control over it. and adding a single regular page just take 10 seconds which is find.

agonist avatar Jan 24 '24 09:01 agonist

I have one project having issues with sitemap on app router while others works fine, it was driving me crazy, I compared versions and downgraded to 4.1.8 and it seems to be working now. This library seems a little abandoned? The oficial sitemap support from nextjs is very basic, how do you even generate sitemaps for static pages generated at build time @agonist ?

It depends on how you generate your static page, but on my side, I generate page based on data from my db, so I'm simply generating my sitemap based on the same data I use to generate static page. Just an example for the idea :

  const tools = await findAllToolsSlugOnly(); // this is my db call

  const allTools = tools.map((t) => {
    const to: R = {
      url: `${site}/ai-tools/${t.slug}`,
      lastModified: new Date(),
      changeFrequency: "daily",
      priority: 0.7,
    };
    return to;
  });

I'm doing something like that. So I have various array of from my static pages for different routes. once setup you don't have to touch it anymore and what's happening is very predictable which make the sitemap less mysterious and give you full control over it. and adding a single regular page just take 10 seconds which is find.

thanks for the suggestion, I kinda liked how this library used to "just works", but I think it's worth doing some refactoring to use the built in support from nextjs and get more predictable results, I wrote a function to map the static pages from the filesystem, now I just need to include pages generated at build time.

evertjr avatar Jan 24 '24 12:01 evertjr

I'm using Next 14 with the pages folder and I'm getting empty sitemaps too. No errors.

AtomSpy avatar Feb 07 '24 15:02 AtomSpy

Getting empty sitemaps even exporting generateStaticParams on my pages. I'm using Next 14 with App directory.

polvallverdu avatar Feb 09 '24 10:02 polvallverdu

you must first build the project, since the library interacts with the .next folder. Also, I added the option generateIndexSitemap: false, in order for me to create only one sitemap.

module.exports = {
    siteUrl: 'https://aksenov-maksim.ru',
    exclude: ['/robots.txt'],
    outDir: './src/app/',
    generateIndexSitemap: false
};

Dlazder avatar Mar 12 '24 13:03 Dlazder

I'm using Next.js 14 and experiencing the same issue.

InsightfulFuture avatar Apr 09 '24 00:04 InsightfulFuture

On my side, I had a root layout (on a approuter next.js 14), and when importing import { headers } from "next/headers";, the sitemap were empty.

tiste avatar Apr 24 '24 06:04 tiste