Registry / testing / fetch-har

fetch-har

JSON →
library12.0.4jsnpmunverified

Make a fetch request from a HAR (HTTP Archive) definition. Current stable version is 12.0.4, requiring Node >=22 and ESM. Converts HAR log entries into native fetch() calls, supporting Node 18+ and all browsers with native fetch. Key differentiators: no polyfills needed, works across browsers and Node, supports file uploads from buffers or File objects, and integrates with mocking libraries like nock or MSW. Maintained by readme.io with cross-browser CI testing.

npm install fetch-har
INSTALL
IMPORT
SIG · FETCH-HAR
F
fetch-har
testingjavascriptv12.0.4
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.

fetchHAR
import fetchHAR from 'fetch-har'
import { fetchHAR } from 'fetch-har'
Default export only; named import will be undefined. ESM-only, no CommonJS.
fetchHAR
import fetchHAR from 'fetch-har'
const fetchHAR = require('fetch-har')
Package is ESM-only since v12 (Node >=22). require() will throw ERR_REQUIRE_ESM.
fetchHAR
import type { Options } from 'fetch-har'
TypeScript types are included. Options type can be imported for customizing requests.

Demonstrates importing fetch-har, constructing a HAR object with an Authorization header, calling fetchHAR, and parsing the JSON response.

import fetchHAR from 'fetch-har'; const har = { log: { entries: [ { request: { method: 'GET', url: 'https://httpbin.org/get', headers: [ { name: 'Authorization', value: 'Bearer ' + (process.env.API_KEY ?? '') }, ], }, }, ], }, }; const response = await fetchHAR(har); const data = await response.json(); console.log(data);
Debug
Known issues
breakingNode >=22 required (v12+). Node 18 or 20 will not work.
fix
Upgrade Node to v22 or later, or downgrade fetch-har to v11.x.
affects: >=12.0.0
gotchafiles option is required for file uploads unless the HAR contains data URLs. Missing both causes a fatal exception.
fix
Always provide a files map when dealing with multipart/form-data HAR entries without data URLs.
affects: *
gotchaThe init option's body and credentials may be overridden by the HAR definition.
fix
Do not rely on custom body/credentials in init if the HAR specifies them.
affects: *
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using CommonJS require() on an ESM-only package.
fix
Use import statement or set type: module in package.json.
TypeError: fetchHAR is not a function
Named import instead of default import: import { fetchHAR } from 'fetch-har'.
fix
Use default import: import fetchHAR from 'fetch-har'.
Error: No files provided for multipart/form-data and no data URL found for parameter 'file'. Fatal exception thrown.
Missing files option or data URL in HAR for a file upload parameter.
fix
Provide a files map with a buffer/File for the parameter name, or add a data URL to the HAR entry.
Upgrade
Version history
12.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

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