Registry / devops / fetch-enhanced

fetch-enhanced

JSON →
library13.0.0jsnpmunverified

fetch-enhanced is a lightweight wrapper around any fetch-like function (e.g., undici, node-fetch) that adds HTTP proxy auto-discovery from environment variables, request timeout support, and accessible agent/dispatcher options. The latest version is 13.0.0, released with a Node.js >=22 requirement and undici as a peer dependency. It ships TypeScript type declarations. Key differentiators include a built-in agent cache (default size 512), explicit noProxy flag, and a dedicated TimeoutError class. It is actively maintained by silverwind.

npm install fetch-enhanced
INSTALL
IMPORT
SIG · FETCH-ENHANCED
F
fetch-enhanced
devopsjavascriptv13.0.0
harness data pending
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.
fix
Upgrade 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.
fix
Always pass `{ undici: true }` when using undici fetch.
affects: >=1.0.0
gotchaIf `agent` option is provided, proxy auto-discovery is disabled entirely.
fix
Do 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`.
fix
Use `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.
fix
Convert 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.
fix
Use `import fetchEnhanced from 'fetch-enhanced'` instead of destructuring.
ERR_REQUIRE_ESM: require() of ES Module
Using require() to load an ESM-only module.
fix
Use dynamic import() or switch to ESM.
Upgrade
Version history
13.0.0latest on npm
Audit
Dependencies
undicioptionalPeer dependency required for undici-specific fetch implementation
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-enhanced — npm install fetch-enhanced · libregistry