Registry / devops / fetch-ponyfill

fetch-ponyfill

JSON →
library7.1.0jsnpmunverified

A WHATWG fetch ponyfill (does not overwrite native fetch) that wraps github/fetch for the browser and delegates to node-fetch in Node.js. Current version 7.1.0. Ships TypeScript types. Ideal for environments where you need fetch without side effects or globals. Returns a setup function that yields fetch, Request, Response, Headers. Supports Promise and XMLHttpRequest options. Maintained, with regular releases.

npm install fetch-ponyfill
INSTALL
IMPORT
SIG · FETCH-PONYFILL
F
fetch-ponyfill
devopsjavascriptv7.1.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.

fetchPonyfill
import fetchPonyfill from 'fetch-ponyfill'; const {fetch} = fetchPonyfill();
import {fetch} from 'fetch-ponyfill';
fetch-ponyfill exports a factory function, not the fetch object directly. You must call it to get fetch.
fetch, Request, Response, Headers
const {fetch, Request, Response, Headers} = require('fetch-ponyfill')(options);
const fetchPonyfill = require('fetch-ponyfill'); const fetch = fetchPonyfill.fetch;
CommonJS usage: require('fetch-ponyfill') gives the factory function, not an object with fetch.
TypeScript types
import fetchPonyfill from 'fetch-ponyfill'; const {fetch} = fetchPonyfill();
Types bundled; works well with TypeScript. No special import needed for types.

Demonstrates importing the factory, calling it with options, and using the fetch function for an HTTP GET request.

import fetchPonyfill from 'fetch-ponyfill'; const {fetch, Request, Response, Headers} = fetchPonyfill({ Promise: globalThis.Promise, }); async function main() { const response = await fetch('https://api.example.com/data'); const data = await response.json(); console.log(data); } main();
Debug
Known issues
breakingVersion 7.0.0 dropped support for Node < 12 and removed deprecated options like 'Request' and 'Headers' as direct exports.
fix
Ensure Node version >=12. Use the factory function to obtain Request, Response, and Headers.
affects: >=7.0.0
gotchaThe exported function is a factory; forgetting to call it will yield undefined for fetch.
fix
Always call fetchPonyfill() (with or without options) before destructuring.
affects: >=1.0.0
deprecatedXMLHttpRequest option is deprecated in browser environment; native fetch is preferred.
fix
Remove XMLHttpRequest option; rely on built-in fetch or provide it only for Firefox OS.
affects: >=6.0.0
gotchaWhen using webpack, ensure you import the default export first, then call it; direct named imports from the package do not exist.
fix
Use `import fetchPonyfill from 'fetch-ponyfill'` instead of `import { fetch } from 'fetch-ponyfill'`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: fetchPonyfill is not a function
Using named import incorrectly (e.g., import { fetch } from 'fetch-ponyfill')
fix
Use default import: import fetchPonyfill from 'fetch-ponyfill'; then call it.
Cannot find module 'node-fetch'
The package requires node-fetch in Node.js but it might not be installed.
fix
Install node-fetch: npm install node-fetch (or it is automatically a dependency).
fetch is not defined
Using the factory but destructuring without calling it.
fix
Correct: const {fetch} = fetchPonyfill(); not const {fetch} = require('fetch-ponyfill');
Upgrade
Version history
7.1.0latest on npm
Audit
Dependencies
node-fetchoptionalused in Node.js environment for actual fetch implementation
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-ponyfill — npm install fetch-ponyfill · libregistry