gatsbyjs/gatsby · error

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

Error message

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

What it means

Thrown by the setRequestHeaders action when either the `headers` argument is not a plain object or the `domain` argument is not a string. The action first emits specific warnings (lines above) describing which argument is bad, then panics. Returns null after panicking.

Source

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

    typeof headers === `object` && headers !== null && !Array.isArray(headers)

  const noHeaders = !headersIsObject
  const noDomain = typeof domain !== `string`

  if (noHeaders) {
    reporter.warn(
      `Plugin ${plugin.name} called actions.setRequestHeaders with a headers property that isn't an object.`
    )
  }

  if (noDomain) {
    reporter.warn(
      `Plugin ${plugin.name} called actions.setRequestHeaders with a domain property that isn't a string.`
    )
  }

  if (noDomain || noHeaders) {
    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(

View on GitHub (pinned to 8b06340921)

Solutions

  1. Pass headers as a plain object (e.g. { 'X-Custom': 'value' }) and domain as a string (e.g. 'example.com').
  2. Guard upstream: if (!domain || typeof headers !== 'object') return before calling the action.
  3. Read the two warnings printed above the panic to see exactly which argument was invalid.

Example fix

// before
actions.setRequestHeaders({ domain: maybeDomain, headers: headerList })
// after
if (typeof maybeDomain === 'string' && headerMap && !Array.isArray(headerMap)) {
  actions.setRequestHeaders({ domain: maybeDomain, headers: headerMap })
}
Defensive patterns

Strategy: validation

Validate before calling

if (typeof domain !== 'string' || !headers || typeof headers !== 'object' || Array.isArray(headers)) {
  throw new Error('setRequestHeaders needs a string domain and a plain object headers')
}
actions.setRequestHeaders({ domain, headers })

Type guard

function isHeadersInput(v): v is { domain: string; headers: Record<string,string> } {
  return v && typeof v.domain === 'string' && !!v.headers && typeof v.headers === 'object' && !Array.isArray(v.headers)
}

Prevention

When it happens

Trigger: A call to actions.setRequestHeaders where headers is null/array/primitive (noHeaders true) OR domain is not a string (noDomain true), or both.

Common situations: Passing an array instead of an object for headers; forgetting to spread a headers map; passing undefined for domain when configuring per-domain headers dynamically; a config-driven loop that yields undefined for some domains.

Related errors


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