Registry / devops / node-fetch-cjs

node-fetch-cjs

JSON →
library3.3.2jsnpmunverified

A CommonJS wrapper for node-fetch v3 that brings the WHATWG Fetch API to Node.js. Version 3.3.2, updated automatically with each node-fetch release. Key differentiator: allows CJS environments to use the ESM-only node-fetch v3 without migration. Bundles fetch-blob and formdata-polyfill for full CJS compatibility. Includes TypeScript types. Use only if you cannot migrate to ESM; otherwise prefer the official node-fetch.

npm install node-fetch-cjs
INSTALL
IMPORT
SIG · NODE-FETCH-CJS
N
node-fetch-cjs
devopsjavascriptv3.3.2
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
const { default: fetch } = require('node-fetch-cjs');
const fetch = require('node-fetch-cjs'); // then fetch is an object, not a function
Recommended destructuring pattern. The default export is named 'default'.
Headers
const { Headers } = require('node-fetch-cjs');
const { Headers } = require('node-fetch-cjs').default; // 'default' is not a namespace
Use named export directly from the CJS export.
Blob
const { Blob } = require('node-fetch-cjs');
const { Blob } = require('node-fetch'); // Blob not exported from official package
Blob is bundled from fetch-blob for convenience.
FormData
const { FormData } = require('node-fetch-cjs');
const { FormData } = require('form-data'); // different API
FormData is bundled from formdata-polyfill for convenience.

Shows how to require and use fetch, Headers, Blob, and FormData from node-fetch-cjs in CJS environment.

const { default: fetch, Headers, Blob, FormData } = require('node-fetch-cjs'); async function main() { const response = await fetch('https://api.github.com/users/github'); const data = await response.json(); console.log('GitHub login:', data.login); // Using Headers const headers = new Headers(); headers.append('Content-Type', 'application/json'); console.log('Headers:', headers.get('Content-Type')); // Using Blob const blob = new Blob(['Hello, world!'], { type: 'text/plain' }); const text = await blob.text(); console.log('Blob text:', text); // Using FormData const form = new FormData(); form.append('key', 'value'); console.log('FormData:', form); } main().catch(console.error);
Debug
Known issues
gotchaconst fetch = require('node-fetch-cjs'); then fetch() does not work; fetch is an object with properties including a 'default' method.
fix
const { default: fetch } = require('node-fetch-cjs');
affects: >=3.0.0
deprecatedLegacy export: const fetch = require('node-fetch-cjs'); fetch.default(...) still works but is not recommended.
fix
Use destructuring import instead.
affects: >=3.0.0
breakingVersion 3.x is a wrapper for ESM-only node-fetch v3; does not support node-fetch v2 API (e.g., fetch.Promise, fetch.isRedirect).
fix
Use only for node-fetch v3 API; do not rely on node-fetch v2-specific properties.
affects: >=3.0.0
gotchaBlob and FormData are bundled; using external polyfills may conflict.
fix
Use Blob and FormData from node-fetch-cjs only; avoid importing from other packages.
affects: >=3.0.0
breakingRequires Node.js ^12.20.0 || ^14.13.1 || >=16.0.0; older Node versions not supported.
fix
Upgrade Node.js to a supported version.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: fetch is not a function
Using const fetch = require('node-fetch-cjs'); then calling fetch() directly, but fetch is an object with default property.
fix
Use const { default: fetch } = require('node-fetch-cjs'); or call fetch.default(...).
Cannot find module 'node-fetch-cjs'
Package not installed or not in node_modules.
fix
Run npm install node-fetch-cjs
Unknown option: --experimental-modules
Trying to use node-fetch-cjs with ESM flags, which is unnecessary since it's CJS.
fix
Remove any --experimental-modules or --es-module-specifier-resolution flags; node-fetch-cjs works with plain require().
Upgrade
Version history
3.3.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
node-fetch-cjs — npm install node-fetch-cjs · libregistry