Node "ReferenceError: structuredClone is not defined" in CI
The structuredClone global was added in Node 17. On Node 16 or earlier the function is undefined, so deep-cloning with it throws a ReferenceError on CI runners pinned to an older version.
What this error means
A structuredClone(obj) call fails with "ReferenceError: structuredClone is not defined" on an older Node runner while working locally.
node
const copy = structuredClone(state);
^
ReferenceError: structuredClone is not definedCommon causes
Runner uses Node older than 17
structuredClone is unavailable before Node 17, so the global reference fails.
A dependency relies on the global at run time
A library calls structuredClone expecting a modern runtime, surfacing the error from inside its code on old Node.
How to fix it
Upgrade the runner Node version
Pin Node 18+ so structuredClone is a built-in global.
.github/workflows/ci.yml
- uses: actions/setup-node@v4
with:
node-version: '20'Polyfill structuredClone on legacy Node
If you cannot upgrade, install a polyfill and assign it to the global early in startup.
index.js
import structuredClone from '@ungap/structured-clone';
globalThis.structuredClone = structuredClone;How to prevent it
- Pin a modern Node version in CI.
- Track the minimum Node your dependencies require.
- Polyfill only as a last resort for legacy runtimes.
Related guides
Node "ReferenceError: fetch is not defined" on older Node in CIFix Node "ReferenceError: fetch is not defined" in CI - the global fetch API is only built in on Node 18+; ol…
Node "Unsupported engine ... required: node" in CIFix npm "Unsupported engine" / "engine node is incompatible" in CI - the runner Node version does not satisfy…
Node "DeprecationWarning: punycode module is deprecated" (DEP0040) in CIFix Node "DeprecationWarning: The punycode module is deprecated" (DEP0040) in CI - a dependency imports the b…