Registry / devops / node-fetch-commonjs

node-fetch-commonjs

JSON →
library3.3.2jsnpmunverified

A CommonJS-compatible fork of node-fetch v3.x that brings the WHATWG Fetch API to Node.js. This package provides the same API as node-fetch v3.3.1 but compiled to CommonJS, allowing require() usage and avoiding the ExperimentalWarning about 'stream/web'. It supports Node.js ^12.20.0, ^14.13.1, or >=16.0.0 and ships TypeScript type definitions. Useful for projects that require CommonJS modules or run on older Node.js versions that don't support node: prefix requires.

npm install node-fetch-commonjs
INSTALL
IMPORT
SIG · NODE-FETCH-COMMONJ
N
node-fetch-commonjs
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 (fetch)
import fetch from 'node-fetch-commonjs'
const fetch = require('node-fetch-commonjs').default
Default import works directly; no need for .default in CommonJS.
Headers
import { Headers } from 'node-fetch-commonjs'
const { Headers } = require('node-fetch-commonjs')
Named export works in both ESM and CJS.
Request
import { Request } from 'node-fetch-commonjs'
Available as named export.
Response
import { Response } from 'node-fetch-commonjs'
Available as named export.
FetchError
import { FetchError } from 'node-fetch-commonjs'
For type checking fetch errors.

Shows basic fetch usage with error handling for non-ok responses.

import fetch from 'node-fetch-commonjs'; async function main() { try { const response = await fetch('https://api.example.com/data', { method: 'GET', headers: { 'Accept': 'application/json' } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } catch (error) { console.error('Fetch failed:', error); } } main();
Debug
Known issues
gotchanode-fetch-commonjs does not support all WHATWG Fetch API features (e.g., abort controller is supported but some edge cases differ)
fix
Check node-fetch documentation for known limitations.
affects: >=3.0.0
deprecatedThe Fetch API is now built-in in Node.js 18+. Consider using native fetch instead.
fix
Use global fetch available in Node >=18, or import from 'node:fetch'.
affects: >=3.0.0
gotchaCommonJS require() may not correctly resolve ESM-only subpath exports.
fix
Use import() syntax or ensure package is fully CommonJS.
affects: >=3.0.0
Errors
Common errors & fixes
ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
node-fetch v3 triggers this warning on some Node versions; node-fetch-commonjs suppresses it
fix
Use node-fetch-commonjs instead of node-fetch to avoid the warning.
Cannot find module 'node-fetch-commonjs'
Package not installed or not in node_modules
fix
Run 'npm install node-fetch-commonjs' or 'yarn add node-fetch-commonjs'
fetch is not a function
Using an older version of Node that doesn't have native fetch and forgetting to import
fix
Add 'import fetch from "node-fetch-commonjs"' at the top of your file.
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-commonjs — npm install node-fetch-commonjs · libregistry