Registry / devops / cross-fetch-ponyfill

cross-fetch-ponyfill

JSON →
library1.0.3jsnpmunverified

A lightweight fetch ponyfill that only provides a fetch polyfill in Node.js environments. In browsers, it uses the native fetch API without modification. This approach avoids unnecessary polyfilling in browsers and ensures minimal overhead. Version 1.0.3 is the latest stable release. The package is updated infrequently, with a simple API that exports a single fetch function. It differentiates itself from other cross-platform fetch libraries by being a true ponyfill (no side effects or global pollution) and only targeting Node.js for polyfilling.

npm install cross-fetch-ponyfill
INSTALL
IMPORT
SIG · CROSS-FETCH-PONYFI
C
cross-fetch-ponyfill
devopsjavascriptv1.0.3
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.

default
✓ import fetch from 'cross-fetch-ponyfill'
✗ import { fetch } from 'cross-fetch-ponyfill'
The default export is a fetch function. A named export is not available.
CommonJS
✓ const fetch = require('cross-fetch-ponyfill')
✗ const { fetch } = require('cross-fetch-ponyfill')
CommonJS users must use default require; destructuring will result in undefined.
TypeScript
✓ import fetch from 'cross-fetch-ponyfill'
✗ import * as fetch from 'cross-fetch-ponyfill'
TypeScript users should use default import; namespace import is not typed correctly.

Shows basic usage: importing fetch as default and making a GET request with async/await.

import fetch from 'cross-fetch-ponyfill'; async function main() { const response = await fetch('https://api.example.com/data'); const data = await response.json(); console.log(data); } main().catch(console.error);
Debug
Known issues
gotchaThis is a ponyfill, not a polyfill. It does not modify global fetch in any environment.
fix
Import the fetch function and use it directly. Do not expect global.fetch to be available.
affects: >=0.0.0
deprecatedThe 'whatwg-fetch' dependency is only installed in Node.js environments; in browsers it is not used. However, whatwg-fetch itself is not actively maintained and may have bugs.
fix
Consider alternatives like 'node-fetch' (for Node 18+ native fetch is stable) or native fetch in modern browsers.
affects: <=1.0.3
gotchaTypeScript users must ensure their tsconfig 'moduleResolution' is set to 'node' or 'node16' to resolve the default export correctly.
fix
Set 'moduleResolution' to 'node' or 'node16' in tsconfig.json.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'cross-fetch-ponyfill' or its corresponding type declarations.
TypeScript cannot find the module because it lacks types.
fix
Install @types/cross-fetch-ponyfill (if available) or declare the module: declare module 'cross-fetch-ponyfill';
TypeError: fetch is not a function
Importing the named export { fetch } instead of the default export.
fix
Use import fetch from 'cross-fetch-ponyfill' (default import) instead of import { fetch } from 'cross-fetch-ponyfill'.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
whatwg-fetchoptionalUsed only in Node.js to polyfill fetch; not bundled in browser builds.
Agent activity
4 hits · last 30 days
node
4
Resources
cross-fetch-ponyfill — npm install cross-fetch-ponyfill · libregistry