Registry / devops / cross-undici-fetch

cross-undici-fetch

JSON →
library0.4.14jsnpmunverified

A cross-platform fetch API ponyfill that provides the WHATWG fetch, Request, Response, and Headers interfaces using undici (Node.js) or native browser/cross-platform implementations. Version 0.4.14 is the latest stable; the package is actively maintained as part of the @whatwg-node family, with frequent releases. It differs from alternatives like 'node-fetch' by leveraging undici for Node.js (faster, HTTP/2 support) and providing TypeScript types out of the box. Designed for isomorphic JavaScript, it ensures consistent fetch semantics across Node.js, Deno, and browsers, with minimal polyfill footprint.

npm install cross-undici-fetch
INSTALL
IMPORT
SIG · CROSS-UNDICI-FETCH
C
cross-undici-fetch
devopsjavascriptv0.4.14
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
import { fetch } from 'cross-undici-fetch'
const fetch = require('cross-undici-fetch').fetch
ESM-only package. Use dynamic import in CommonJS.
Request
import { Request } from 'cross-undici-fetch'
const Request = require('cross-undici-fetch').Request
Named export. Cannot be used with require.
Response
import { Response } from 'cross-undici-fetch'
Named export, ESM only.
Headers
import { Headers } from 'cross-undici-fetch'
import Headers from 'cross-undici-fetch'
Not a default export. Must use named import.

Demonstrates basic usage of the fetch ponyfill with POST request and JSON response parsing.

import { fetch } from 'cross-undici-fetch'; async function main() { const res = await fetch('https://api.example.com/data', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: 'value' }), }); const data = await res.json(); console.log(data); } main();
Debug
Known issues
breakingVersion 0.4.x drops CommonJS support; require() will not work.
fix
Use dynamic import: const { fetch } = await import('cross-undici-fetch');
affects: >=0.4.0
deprecatedThis package is deprecated in favor of @whatwg-node/fetch.
fix
Migrate to @whatwg-node/fetch (same API, better maintenance).
affects: >=0.4.0
gotchaIn Node.js < 18, web-streams-polyfill may be needed for stream support.
fix
Install web-streams-polyfill: npm install web-streams-polyfill
affects: >=0.4.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'cross-undici-fetch'
Using require() in CommonJS module. This package is ESM-only from v0.4.
fix
Use dynamic import: const { fetch } = await import('cross-undici-fetch');
TypeError: fetch is not a function
Incorrect import: using default import instead of named import.
fix
Use named import: import { fetch } from 'cross-undici-fetch';
Upgrade
Version history
0.4.14latest on npm
Audit
Dependencies
undicirequiredProvides the fetch implementation in Node.js environments.
web-streams-polyfilloptionalPolyfills WHATWG Streams for older Node.js versions (pre-v18).
Agent activity
8 hits · last 30 days
node
8
Resources
cross-undici-fetch — npm install cross-undici-fetch · libregistry