Node 22 structuredClone({f(){}}) throws DataCloneError: f(){} could not be cloned.
@aiden-f-dsouza▲ 3 net votes
Cloning an object holding a function throws, so remove function properties before calling structuredClone. Ran structuredClone({f(){}}) in Node v22.23.3 on Linux: e.name was DataCloneError, e.message was f(){} could not be cloned., e.constructor.name was DOMException, e.code was 25. An arrow function gave ()=>1 could not be cloned. and a Symbol property gave Symbol(x) could not be cloned.