Registry / devops / fetch-dedupe

fetch-dedupe

JSON →
library3.0.0jsnpmunverified

A lightweight, fetch-compatible HTTP client (v3.0.0) that transparently deduplicates identical in-flight requests and caches responses to improve performance in complex web apps. Unlike raw fetch, it groups concurrent requests with the same URL, method, and body into a single network call, and can cache responses for subsequent requests. It exports a fetchDedupe function, cache management utilities, and error types. Works in browsers and Node 18+ with global fetch.

npm install fetch-dedupe
INSTALL
IMPORT
SIG · FETCH-DEDUPE
F
fetch-dedupe
devopsjavascriptv3.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.

fetchDedupe
import { fetchDedupe } from 'fetch-dedupe'
import fetchDedupe from 'fetch-dedupe'
This library exports named exports only. Default import will yield undefined.
responseCache
import { responseCache } from 'fetch-dedupe'
const { responseCache } = require('fetch-dedupe')
If using CommonJS in Node < 18, use const { fetchDedupe, responseCache } = require('fetch-dedupe').
activeRequests
import { activeRequests } from 'fetch-dedupe'
import { activeRequests } from 'fetch-dedupe/activeRequests'
All exports are at the package root; there are no subpath exports.
CacheMissError
import { CacheMissError } from 'fetch-dedupe'
Error class for cache misses when using responseCache.get().

Shows how to use fetchDedupe as a drop-in fetch replacement that dedupes concurrent requests.

import { fetchDedupe } from 'fetch-dedupe'; async function demo() { const data = await fetchDedupe('/api/data'); console.log('Response:', data); } demo();
Debug
Known issues
breakingv3 drops Node < 18 support and requires a global fetch implementation (e.g., Node 18+ or a polyfill).
fix
Upgrade to Node 18 or later, or use a fetch polyfill like undici or node-fetch.
affects: >=3.0.0
breakingv3 removes the ability to pass a plain string URL as first argument without options? Actually, still supported. Check documentation.
fix
URL as first argument still works; no change needed.
affects: >=3.0.0
deprecatedThe `responseType` option as a string is deprecated. Use `responseType` as a function in v3.
fix
Pass a function: responseType: (res) => res.status === 204 ? 'text' : 'json'
affects: >=3.0.0
gotchaThe `responseCache` is a global, shared cache. If you need per-request caching, manage your own cache.
fix
Use responseCache.clear() between tests or create isolated contexts.
affects: >=0.0.0
gotchaThe `requestKey` option defaults to URL + method + body. If you mutate the body (e.g., JSON.stringify), two identical requests may not dedupe if body order differs.
fix
Pass a custom requestKey to normalize body ordering.
affects: >=0.0.0
gotchaThe library does not handle fetch errors (network failures) – those rejections are passed through as-is.
fix
Always add a .catch() or try/catch around fetchDedupe.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: fetchDedupe is not a function
Using default import instead of named import.
fix
Change to: import { fetchDedupe } from 'fetch-dedupe';
window.fetch is not a function
Using fetch-dedupe in an environment without a global fetch (e.g., older Node).
fix
Install a fetch polyfill and set globalThis.fetch = require('node-fetch');
UnhandledPromiseRejection: TypeError: Failed to fetch
Network error or CORS issue; fetch-dedupe does not wrap fetch errors.
fix
Add a catch block: fetchDedupe('/api').catch(err => console.error(err));
Cannot read properties of undefined (reading 'json')
Response type parsing failed; often because response body is empty or wrong content-type.
fix
Set responseType explicitly or handle non-JSON responses with a function.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fetch-dedupe — npm install fetch-dedupe · libregistry