Registry / devops / fetch-nodeshim

fetch-nodeshim

JSON →
library0.4.10jsnpmunverified

A lightweight fetch shim for Node.js that uses the environment's built-in Request, Response, and Headers classes (globals) but replaces the fetch implementation with calls into node:http and node:https. Version 0.4.10 is the latest stable release. Unlike @remix-run/web-fetch or undici-based shims, this avoids Node.js' built-in fetch (which may use an older undici) and provides a more permissive, patched-free implementation. Ships TypeScript types and is ESM-only.

npm install fetch-nodeshim
INSTALL
IMPORT
SIG · FETCH-NODESHIM
F
fetch-nodeshim
devopsjavascriptv0.4.10
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 'fetch-nodeshim'
import { fetch } from 'fetch-nodeshim'
Default export only. Do not use named import.
Request
import { Request } from 'fetch-nodeshim'
import Request from 'fetch-nodeshim'
Request is re-exported from globals; available as named export.
Response
import { Response } from 'fetch-nodeshim'
import Response from 'fetch-nodeshim'
Response is re-exported from globals; available as named export.

Shows basic usage of the default fetch export with GET request and JSON parsing.

import fetch from 'fetch-nodeshim'; async function main() { const response = await fetch('https://api.example.com/data', { method: 'GET', headers: { 'Content-Type': 'application/json' }, }); 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
gotchaUses node:http/https instead of native fetch, so features like streaming uploads may have different behavior.
fix
Test thoroughly if relying on advanced fetch features; consider using native fetch if available.
affects: >=0.1.0
gotchaRequires Node.js 18+ because it depends on global Request, Response, and Headers (available as globals from Node 18).
fix
Upgrade Node.js to 18+ or use a polyfill for these globals.
affects: >=0.4.0
breakingVersion 0.4.0 dropped CommonJS support; package is ESM-only.
fix
Use ES modules (type: module in package.json or .mjs extensions).
affects: >=0.4.0
deprecatedThe 'node-fetch' compatibility export was removed in v0.3.0.
fix
Switch to default import instead of require('fetch-nodeshim/node-fetch').
affects: >=0.3.0
Errors
Common errors & fixes
Error: fetch is not a function
Using named import { fetch } instead of default import.
fix
Use import fetch from 'fetch-nodeshim' (no braces).
ReferenceError: Request is not defined
Running on Node.js <18 without polyfill for global Request.
fix
Upgrade to Node.js 18+ or add a polyfill (e.g., undici).
Cannot find module 'fetch-nodeshim'
Attempting to require() in a CommonJS project without dynamic import.
fix
Use dynamic import: const fetch = (await import('fetch-nodeshim')).default; or switch to ES modules.
Upgrade
Version history
0.4.10latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fetch-nodeshim — npm install fetch-nodeshim · libregistry