コンテンツにスキップ

[WARN] [@astrojs/sitemap] The Sitemap integration requires the ...

Astroでビルドを実行した際、ターミナルに以下のような警告が出力され、サイトマップが生成されない場合がある。

この警告は、Cloudflare Pagesなどの環境でAstroをビルドしたときにも見られる。原因は astro.config.mjssite オプションが設定されていないため、サイトマップの基準URLが特定できず、生成処理がスキップされていることである。

解決策:astro.config.mjsにsiteを追加する

Section titled “解決策:astro.config.mjsにsiteを追加する”

警告文が示す通り、astro.config.mjs にサイトの基本URLを指定する site プロパティを追加すれば解決する。

  1. astro.config.mjs を開く。

  2. defineConfig 内に site: 'https://あなたのドメイン.com' を追記する。

    astro.config.mjs
    // astro.config.mjs
    export default defineConfig({
    site: 'https://xxx.example.com',
    integrations: [...],
    // ...
    });
  3. 設定を保存し、再度ビルドを実行する。

これにより、ビルド時に public または dist ディレクトリへ sitemap-index.xml が正常に作成される(例: sitemap-index.xml)。

  • Astroビルド時のサイトマップ関連警告は、astro.config.mjs での site 指定漏れが原因である。
  • defineConfig 内に自身のWebサイトのURLを site: 'https://...' として追記することで警告は消え、サイトマップが生成される。

参考サイト

環境情報

  • node : v20.15.1
  • astro: 4.13.1
  • @astrojs/starlight: 0.25.4

他の記事を探す