Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default export
✓ import fetchEnhanced from 'fetch-enhanced'
✗ const fetchEnhanced = require('fetch-enhanced')
Package is ESM-only since v13; CommonJS require will fail.
TimeoutError
✓ import { TimeoutError } from 'fetch-enhanced'
✗ import TimeoutError from 'fetch-enhanced'
TimeoutError is a named export, not default.
clearCache
✓ import fetchEnhanced from 'fetch-enhanced';
const fetch = fetchEnhanced(impl);
fetch.clearCache();
✗ import { clearCache } from 'fetch-enhanced'
clearCache is a method on the wrapped fetch function, not a direct export.
Demonstrates basic usage: wrap an undici fetch, set a 5-second timeout, and handle TimeoutError.
import { fetch as undiciFetch } from 'undici';
import fetchEnhanced from 'fetch-enhanced';
const fetch = fetchEnhanced(undiciFetch, { undici: true });
async function main() {
try {
const res = await fetch('https://httpbin.org/anything', { timeout: 5000 });
console.log(await res.json());
} catch (err) {
if (err instanceof TimeoutError) {
console.error('Request timed out');
} else {
console.error(err);
}
}
}
main();
Debug
Known issues
breakingVersion 13 drops Node.js <22 support and switches to ESM-only.fixUpgrade Node.js to >=22 and use ES modules (import syntax).
affects: >=13.0.0
gotchaThe `undici: true` option is required when wrapping undici fetch; omitting it causes incorrect agent handling.fixAlways pass `{ undici: true }` when using undici fetch. affects: >=1.0.0
gotchaIf `agent` option is provided, proxy auto-discovery is disabled entirely.fixDo not set `agent` if you need proxy support; use `agentOpts` instead.
affects: >=1.0.0
deprecatedThe `agentOpts.noProxy` option is deprecated in favor of top-level `noProxy`.fixUse `noProxy: true` at the top level of fetch options.
affects: >=12.0.0 <13.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using CommonJS require() on an ESM-only package.
fixConvert to ES module (use 'import' or set type:'module' in package.json).
TypeError: fetchEnhanced is not a function
Importing the named export incorrectly for default export.
fixUse `import fetchEnhanced from 'fetch-enhanced'` instead of destructuring.
ERR_REQUIRE_ESM: require() of ES Module
Using require() to load an ESM-only module.
fixUse dynamic import() or switch to ESM.
Audit
Dependencies
undicioptionalPeer dependency required for undici-specific fetch implementation