Registry / testing / unfetch

unfetch

JSON →
library5.0.0jsnpmunverified

A minimal 500-byte fetch polyfill that provides a subset of the standard fetch API. Version 5.0.0 is the current stable release, maintained infrequently as it is feature-complete. Unlike larger alternatives (e.g., whatwg-fetch), unfetch focuses on bare-bones functionality: it only supports text and JSON responses, uses Arrays instead of Iterables, and has no streaming support. It works as both a polyfill (auto-installs on window.fetch) and a ponyfill (importable function). TypeScript types are included. Requires a Promise polyfill for IE11 and below.

npm install unfetch
INSTALL
IMPORT
SIG · UNFETCH
U
unfetch
testingjavascriptv5.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.

fetch (polyfill)
import 'unfetch/polyfill'
import fetch from 'unfetch/polyfill'
Polyfill mode auto-installs fetch on window. No need to import a symbol. (ESM)
fetch (ponyfill)
import fetch from 'unfetch'
import { fetch } from 'unfetch'
Ponyfill mode returns a local fetch function; it is a default export.
fetch (CommonJS ponyfill)
const fetch = require('unfetch')
const { fetch } = require('unfetch')
CommonJS require yields the default export as the entire module.

Demonstrates basic fetch usage with unfetch as a ponyfill for typed environments.

import fetch from 'unfetch'; fetch('https://api.example.com/data') .then(response => { if (!response.ok) throw new Error('Network response was not ok'); return response.json(); }) .then(data => console.log(data)) .catch(err => console.error('Fetch failed:', err)); // Using the polyfill (global): // import 'unfetch/polyfill'; // fetch('/relative/path').then(r => r.text()).then(console.log);
Debug
Known issues
gotchaunfetch does not support streaming responses (e.g., response.body is undefined).
fix
Use alternatives like whatwg-fetch if streaming is required.
affects: >=1.0.0
gotchaunfetch does not support the full Fetch spec: no Request, Response, Headers constructors, no AbortController, no credentials option.
fix
Use a more complete polyfill if those features are needed.
affects: >=1.0.0
gotchaunfetch returns a Promise that resolves to a response with only ok, status, statusText, headers (Map-like), text(), json(), and headers.get() methods.
fix
Do not rely on blob(), arrayBuffer(), formData(), or other methods.
affects: >=1.0.0
gotchaIn polyfill mode, unfetch may override existing window.fetch even if it is a native implementation (it checks for fetch, but may override a non-standard implementation).
fix
Use ponyfill mode if you need to preserve an existing fetch implementation.
affects: >=1.0.0
gotchaunfetch requires a global Promise to be available for older browsers (IE11 and below).
fix
Include a Promise polyfill (e.g., es6-promise) before unfetch.
affects: >=1.0.0
deprecatedThe UMD bundle (unfetch/dist/unfetch.umd.js) is deprecated in favor of ESM or the polyfill script.
fix
Use import 'unfetch/polyfill' or <script src="https://unpkg.com/unfetch/polyfill"></script>.
affects: >=4.0.0
Errors
Common errors & fixes
Uncaught TypeError: Failed to fetch
unfetch's fetch throws a TypeError for network errors, but the message varies across browsers.
fix
Catch the error and check the message pattern; or use the ponyfill which rejects with a TypeError.
Import 'unfetch/polyfill' does not export 'fetch'
The polyfill module does not have a default export; it only side-effects.
fix
Use import 'unfetch/polyfill' (no symbol) to apply the polyfill globally.
TypeError: response.json is not a function
Response object from unfetch does not have json() if it's not a valid response (e.g., network error).
fix
Check response.ok before calling response.json().
Uncaught (in promise) TypeError: response.headers.get is not a function
In older versions of unfetch (< 4.0.0), headers object might be missing or not iterable.
fix
Update to unfetch@5 or access headers as a plain object via response.headers property.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
unfetch — npm install unfetch · libregistry