gatsbyjs/gatsby · error

Plugin ${plugin.name} attempted to set request headers for a

Error message

Plugin ${plugin.name} attempted to set request headers for a domain that is not a valid URL. (${domain})

What it means

Thrown by setRequestHeaders when `domain` is a string but url.parse(domain).hostname is falsy: the string is not a parseable URL. The action cannot determine the base domain to key the headers on, so it panics with the offending domain value and returns null.

Source

Thrown at packages/gatsby/src/redux/actions/public.js:1520

    reporter.panic(
      `Plugin ${plugin.name} attempted to set request headers with invalid arguments. See above warnings for more info.`
    )

    return null
  }

  const baseDomain = url.parse(domain)?.hostname

  if (baseDomain) {
    return {
      type: `SET_REQUEST_HEADERS`,
      payload: {
        domain: baseDomain,
        headers,
      },
    }
  } else {
    reporter.panic(
      `Plugin ${plugin.name} attempted to set request headers for a domain that is not a valid URL. (${domain})`
    )

    return null
  }
}

module.exports = { actions }

View on GitHub (pinned to 8b06340921)

Solutions

  1. Pass a fully-qualified URL or hostname string, e.g. 'https://example.com' or 'example.com'.
  2. Validate the domain before calling: ensure new URL(domain) (or url.parse) yields a hostname.
  3. Filter out empty/undefined domain values from config-driven loops.

Example fix

// before
actions.setRequestHeaders({ domain: rawConfig.url, headers })
// after
const hostname = rawConfig.url && new URL(rawConfig.url).hostname
if (hostname) actions.setRequestHeaders({ domain: hostname, headers })
Defensive patterns

Strategy: validation

Validate before calling

let hostname
try { hostname = new URL(domain).hostname } catch { hostname = '' }
if (!hostname) throw new Error(`setRequestHeaders domain is not a valid URL: ${domain}`)
actions.setRequestHeaders({ domain, headers })

Type guard

function isValidDomainUrl(d: string): boolean {
  try { return Boolean(new URL(d).hostname) } catch { return false }
}

Prevention

When it happens

Trigger: domain is a string but malformed: empty, a bare scheme like 'http://', a string with no hostname (e.g. '/path' or '://'), or whitespace-only.

Common situations: Reading domains from config where one entry is empty; constructing domain dynamically (e.g. `${sub}.${base}` with undefined base); passing a path or protocol instead of a host.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/acc4e859996a6af3. Report an issue: GitHub.