Skip to content
Latchkey

Node "ERR_INVALID_THIS" (undici fetch) in CI

undici (the engine behind global fetch) threw ERR_INVALID_THIS because a Headers/Request method was called with the wrong receiver - typically a fetch polyfill clashing with the built-in global on an older Node.

What this error means

A network call or a tool using fetch fails with "TypeError [ERR_INVALID_THIS]: Value of this must be of type Headers". It often appears after a dependency upgrade or on a pinned older Node version.

node
TypeError [ERR_INVALID_THIS]: Value of "this" must be of type Headers
    at Headers.append (node:internal/deps/undici/undici:...)

Common causes

Polyfill clashing with built-in fetch

A fetch/Headers polyfill is loaded over the native global, so methods receive an incompatible this.

Outdated Node with a newer undici expectation

A library assumes a newer undici/fetch than the pinned Node ships, triggering the receiver check.

How to fix it

Use a supported Node and drop the polyfill

Run a Node version with native fetch and remove redundant fetch polyfills.

workflow
# .nvmrc / workflow
node-version: 20
# remove node-fetch / whatwg-fetch polyfills when on Node 18+

Align undici across dependencies

If a library pins its own undici, dedupe so a single compatible version is used.

Terminal
npm dedupe
npm ls undici

How to prevent it

  • Use native fetch on Node 18+ instead of polyfills.
  • Keep a single undici version via dedupe.
  • Pin a Node version that matches your libraries fetch expectations.

Frequently asked questions

What causes ""ERR_INVALID_THIS (undici fetch)""?
A fetch/Headers polyfill is loaded over the native global, so methods receive an incompatible this.
How do I fix "ERR_INVALID_THIS (undici fetch)"?
Run a Node version with native fetch and remove redundant fetch polyfills.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card