Registry / devops / tenacious-fetch

tenacious-fetch

JSON →
library2.3.1jsnpmunverified

Tiny fetch API wrapper (ESM) adding retry with exponential backoff, configurable timeout, and custom retry strategies. Current stable version 2.3.1, lightweight (~3KB gzipped), zero runtime dependencies. Supports both browser and Node.js (fetch-compatible). Differentiators: minimal overhead, terse API, and full TypeScript definitions (since v2).

npm install tenacious-fetch
INSTALL
IMPORT
SIG · TENACIOUS-FETCH
T
tenacious-fetch
devopsjavascriptv2.3.1
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.

tenaciousFetch
import tenaciousFetch from 'tenacious-fetch'
const { tenaciousFetch } = require('tenacious-fetch')
Default export only; package is ESM-only since v2.
interface TenaciousOptions
import type { TenaciousOptions } from 'tenacious-fetch'
import { TenaciousOptions } from 'tenacious-fetch'
Use 'import type' for TypeScript to avoid emitting runtime code.
tenaciousFetch
const { default: tenaciousFetch } = await import('tenacious-fetch')
const tenaciousFetch = require('tenacious-fetch').default
When using dynamic import in Node ESM.
tenaciousFetch
const tenaciousFetch = require('tenacious-fetch')
CJS import works via default export compatibility (package.json 'exports' field provides CommonJS wrapper).

Shows a basic GET request with 3 retries, 1s delay, and 5s timeout using the default export.

import tenaciousFetch from 'tenacious-fetch'; async function main() { const url = 'https://jsonplaceholder.typicode.com/todos/1'; const options = { retries: 3, retryDelay: 1000, // ms between retries timeout: 5000, // total request timeout onRetry: (attempt, error) => { console.log(`Retry attempt ${attempt} after error: ${error}`); }, }; try { const response = await tenaciousFetch(url, options); const data = await response.json(); console.log('Success:', data); } catch (error) { console.error('Failed after retries:', error); } } main();
Debug
Known issues
breakingtenacious-fetch v2 changed from CommonJS to ESM-only. Direct require() will fail unless using Node >=14 with experimental modules or a compatible bundler.
fix
Use import syntax; if using CommonJS, use dynamic import via async function or update package.json to include 'type': 'module'.
affects: >=2.0.0
gotchaThe 'timeout' option applies to the total request duration including retries, not per attempt. This can cause unexpected early termination.
fix
Calculate per-attempt timeout manually if needed, or use a custom retry strategy.
affects: >=1.0.0
deprecatedThe 'retryMethod' option was deprecated in v2.3.0; use 'retryStrategy' instead (function returning boolean).
fix
Replace `retryMethod` with `retryStrategy` returning true/false.
affects: >=2.3.0
gotchaIf the fetch API is not globally available (e.g., older Node versions), tenacious-fetch will throw a ReferenceError. It does not polyfill fetch.
fix
Install a fetch polyfill like `node-fetch` or `cross-fetch` and assign to globalThis before using.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using ES import syntax in a CommonJS file without enabling ESM support.
fix
Add `"type": "module"` to your package.json, or rename file to .mjs, or use dynamic import.
TypeError: tenaciousFetch is not a function
Using named import instead of default import.
fix
Use `import tenaciousFetch from 'tenacious-fetch'` (default import) instead of `import { tenaciousFetch } from 'tenacious-fetch'`.
ReferenceError: fetch is not defined
tenacious-fetch expects a global fetch implementation; missing in Node <18 or some environments.
fix
Install and import a fetch polyfill before using tenacious-fetch, e.g., `import 'node-fetch'` or `import 'cross-fetch/polyfill'`.
Upgrade
Version history
2.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Resources
tenacious-fetch — npm install tenacious-fetch · libregistry