Registry / testing / universal-fetch

universal-fetch

JSON →
library1.0.0jsnpmunverified

Universal WHATWG Fetch API polyfill for Node.js and browsers including IE8. Version 1.0.0 (latest). This package adds a global `fetch` function, built on top of GitHub's fetch polyfill. It requires an ES6 Promise polyfill (e.g., es6-promise) and does not bundle one. It is designed for use with bundlers like Webpack or Browserify. Compared to isomorphic-fetch, it adds IE8 support but has been largely superseded by native fetch and modern polyfills like whatwg-fetch.

npm install universal-fetch
INSTALL
IMPORT
SIG · UNIVERSAL-FETCH
U
universal-fetch
testingjavascriptv1.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.

global fetch
✓ import 'es6-promise/auto'; import 'universal-fetch';
✗ import fetch from 'universal-fetch';
universal-fetch sets fetch as a global side effect; it does not export fetch. You must import the package for its side effects only. Also requires an ES6 Promise polyfill.
CommonJS require
✓ require('es6-promise').polyfill(); require('universal-fetch');
✗ const fetch = require('universal-fetch');
Using require('universal-fetch') returns an empty object; fetch is set globally. The Promise polyfill must be polyfilled before loading universal-fetch.
TypeScript types
✓ No types provided; use @types/whatwg-fetch or declare global fetch
✗ import { fetch } from 'universal-fetch';
This package does not ship TypeScript definitions. Add '@types/whatwg-fetch' to your devDependencies or manually declare the global fetch function.

Shows global fetch usage after requiring both es6-promise polyfill and universal-fetch side-effect import.

// Install: npm install universal-fetch es6-promise // Then in your entry file: require('es6-promise').polyfill(); require('universal-fetch'); fetch('https://jsonplaceholder.typicode.com/posts/1') .then(function(response) { if (!response.ok) throw new Error('Network response was not ok'); return response.json(); }) .then(function(post) { console.log(post.title); }) .catch(function(error) { console.error('Fetch error:', error); });
Debug
Known issues
deprecatedPackage is unmaintained (last update 2016). Use native fetch or whatwg-fetch instead.
fix
Replace with whatwg-fetch for browsers and native fetch in Node 18+.
affects: >=1.0.0
gotchaRequires a separate ES6 Promise polyfill; not bundled.
fix
Install es6-promise and call polyfill() before loading universal-fetch.
affects: >=0.0.0
gotchaDoes not export fetch; it sets fetch as a global. Direct import or require returns an empty object.
fix
Use side-effect import only: import 'universal-fetch'; then use global fetch.
affects: >=0.0.0
gotchaNo TypeScript types included. TypeScript builds will error on global fetch without type declarations.
fix
Install @types/whatwg-fetch or declare 'declare var fetch: typeof globalThis.fetch;'
affects: >=0.0.0
Errors
Common errors & fixes
fetch is not defined
universal-fetch not loaded, or loaded before Promise polyfill.
fix
Ensure es6-promise polyfill is called before importing universal-fetch, and that the side-effect import is present.
Cannot find module 'universal-fetch'
Package not installed, or typo in import path.
fix
Run: npm install universal-fetch es6-promise
Uncaught TypeError: Failed to fetch
CORS issue or network error; or fetch not supported in older browser without polyfill.
fix
Check the URL and CORS headers. Ensure universal-fetch is loaded as polyfill.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
universal-fetch — npm install universal-fetch · libregistry