nuxt-community / sitemap-module

Sitemap Module for Nuxt 2
https://sitemap.nuxtjs.org
MIT License
690 stars 128 forks source link

FATAL [sitemap-module] The hostname option is mandatory in your config on spa or generate build mode #196

Closed JenuelDev closed 3 years ago

JenuelDev commented 3 years ago

Version

2.15.4

Reproduction link

https://codesandbox.io/s/xenodochial-tree-xr79x?file=/pages/index.vue

Steps to reproduce

Just added the moduel using yarn add @nuxtjs/sitemap, this is my config.

Modules

modules: [
        // https://go.nuxtjs.dev/axios
        '@nuxtjs/axios',
        // https://go.nuxtjs.dev/pwa
        '@nuxtjs/pwa',
        // https://go.nuxtjs.dev/content
        '@nuxt/content',
        '@nuxtjs/dayjs',
        // keep this module at the end
        '@nuxtjs/sitemap',
    ],

Sitemap options

 sitemap: {
        // options
        hostname: process.env.main_base_URL,
        gzip: true,
        exclude: ['/secret', '/admin/**'],
        routes: [
            '/about',
            '/contact',
            {
                url: '/view/javascript-tips-tricks-n1',
                changefreq: 'daily',
                priority: 1,
                lastmodISO: '2017-06-30T13:30:00.000Z',
            },
        ],
    },

What is expected ?

Should generate a sitemap

What is actually happening?

instead an error pops up that says: [sitemap-module] The hostname option is mandatory in your config on spa or generate build mode

This bug report is available on Nuxt community (#c139)
olets commented 3 years ago

Fwiw I don't have this problem:

  sitemap: {
    hostname: process.env.SITEMAP_HOSTNAME,
  }

is working.

NicoPennec commented 3 years ago

@BroJenuel as explained in the error message, the hostname value is mandatory in static target. But your main_base_URL is empty during the nuxt.config.jsscript execution because your Nuxt var envs are setted by that same file.

You have to use a constant as follows:


const main_base_URL =  'https://brojenuel-blog.ml';

export default {
   sitemap: {
        hostname: main_base_URL
    },
    env: {
        main_base_URL
    },
    ...
}
slim-python commented 3 years ago
sitemap: {
        hostname: main_base_URL
    },
    env: {
        main_base_URL
    },

thanks it worked

lumos94 commented 2 years ago

@BroJenuel as explained in the error message, the hostname value is mandatory in static target. But your main_base_URL is empty during the nuxt.config.jsscript execution because your Nuxt var envs are setted by that same file.

You have to use a constant as follows:

const main_base_URL =  'https://brojenuel-blog.ml';

export default {
   sitemap: {
        hostname: main_base_URL
    },
    env: {
        main_base_URL
    },
    ...
}

this doesn't work for me.. was getting this error:


[fatal] [sitemap-module] The `hostname` option is mandatory in your config on `spa` or `generate` build mode 
{
  "path": "/sitemap.xml",
  "exclude": [
    "/verify",
    "/resetpassword"
  ],
  "routes": [],
  "cacheTime": 900000,
  "etag": {
    "weak": false
  },
  "gzip": true,
  "trailingSlash": false,
  "i18n": {
    "locales": [
      "en"
    ],
    "routesNameSeparator": "/"
  },
  "defaults": {},
  "pathGzip": "/sitemap.xml.gz"
}
 Nuxt Fatal Error: [sitemap-module] The `hostname` option is mandatory in your config on  `spa` or  `generate` build mode