Registry / devops / minipass-fetch

minipass-fetch

JSON →
library6.0.0jsnpmunverified

An implementation of the WHATWG Fetch API for Node.js using Minipass streams. Version 6.0.0 requires Node >=22.22.2. This fork reimplements node-fetch with Minipass streams, offering faster and more deterministic timing. It differs from node-fetch by returning Minipass streams instead of Node core streams, and supports full TLS options for https requests. The API mirrors node-fetch, making it a drop-in replacement for streaming use cases.

npm install minipass-fetch
INSTALL
IMPORT
SIG · MINIPASS-FETCH
M
minipass-fetch
devopsjavascriptv6.0.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.

fetch
import fetch from 'minipass-fetch'
const fetch = require('minipass-fetch')
This is ESM-only; CommonJS require will not work. The default export is the fetch function.
Headers
import { Headers } from 'minipass-fetch'
const { Headers } = require('minipass-fetch')
Named exports must be imported with destructuring in ESM; require() will fail.
Request
import { Request } from 'minipass-fetch'
import Request from 'minipass-fetch/Request'
Subpath imports are not supported; always import from the main package.
Response
import { Response } from 'minipass-fetch'
const Response = require('minipass-fetch').Response
ESM-only; use named import.

Imports the default fetch function and makes a GET request with an Authorization header, parsing JSON response.

import fetch from 'minipass-fetch'; async function main() { const url = 'https://api.example.com/data'; const auth = process.env.API_KEY ?? ''; const response = await fetch(url, { headers: { 'Authorization': `Bearer ${auth}` }, }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } main().catch(console.error);
Debug
Known issues
breakingESM-only: This package does not support CommonJS require() since version 5.0.0.
fix
Use import statements. If you must use CommonJS, use dynamic import: const fetch = (await import('minipass-fetch')).default;
affects: >=5.0.0
breakingStreams are Minipass streams, not Node core streams. Methods like .body returns a Minipass stream instead of a Node Readable.
fix
Use Minipass stream methods (e.g., .on('data'), .pipe()). Do not assume node core stream API.
affects: >=1.0.0
deprecatedThe 'buffer' option for response.body is deprecated; use .arrayBuffer() instead.
fix
Replace response.buffer() with response.arrayBuffer().
affects: >=4.0.0
gotchaThe 'json' method returns a Promise that resolves with the parsed JSON; do not await twice.
fix
Use const data = await response.json(); not const text = await response.text(); const data = JSON.parse(text);
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Trying to use require('minipass-fetch') in a CommonJS context
fix
Use import fetch from 'minipass-fetch' or dynamic import: const fetch = (await import('minipass-fetch')).default;
TypeError: response.body.pipe is not a function
Trying to pipe the response body assuming it's a Node Readable stream
fix
The body is a Minipass stream. Use Minipass methods like .on('data') or .pipe() from minipass. Alternatively, use response.buffer() or response.text().
TypeError: fetch is not a function
Incorrect import: using named import instead of default import
fix
Correct import: import fetch from 'minipass-fetch'; (not import { fetch } from ...)
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
minipassrequiredUsed for stream implementation; required runtime dependency
node-fetchoptionalAPI reference; not a direct dependency but the spec this package implements
Agent activity
4 hits · last 30 days
node
4
Resources
minipass-fetch — npm install minipass-fetch · libregistry