Registry / devops / native-fetch

native-fetch

JSON →
library4.0.2jsnpmunverified

A polyfill-aware module that returns the native fetch/Request/Headers API if available in the runtime, otherwise falls back to the undici module. Version 4.0.2 is the current stable release; the package has frequent updates aligned with undici releases. Key differentiator: unlike node-fetch, it uses WHATWG streams for type compatibility and provides a seamless way to write isomorphic code without heavy-handed bundler overrides. Ships TypeScript types. Requires undici as a peer dependency.

npm install native-fetch
INSTALL
IMPORT
SIG · NATIVE-FETCH
N
native-fetch
devopsjavascriptv4.0.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.

fetch
import { fetch } from 'native-fetch'
const fetch = require('native-fetch')
ESM-only since v4; CommonJS require is not supported.
Request
import { Request } from 'native-fetch'
const Request = require('native-fetch').Request
Named export, not default. Available in ESM only.
Headers
import { Headers } from 'native-fetch'
Named export, not default. Available in ESM only.

Demonstrates using the fetch export from native-fetch with async/await to make a GET request and parse JSON response.

import { fetch } from 'native-fetch'; const response = await fetch('https://api.github.com'); const data = await response.json(); console.log(data);
Debug
Known issues
breakingVersion 4.x drops CommonJS support; require() will fail.
fix
Switch to ESM imports: `import { fetch } from 'native-fetch'`
affects: >=4.0.0
deprecatedVersion 3.x and earlier used undici v5; newer peers require undici v6 or later.
fix
Update undici to v6+ if using native-fetch v4.
affects: <4.0.0
gotchaIn Electron renderer process, native fetch may be available but not identical to standard; undici fallback is used only if native fetch is absent.
fix
Test both paths if you need consistent behavior across environments.
affects: >=1.0.0
gotchaThe package does not polyfill AbortController; you must provide your own if needed.
fix
Import or polyfill AbortController separately.
affects: >=1.0.0
deprecatedVersion 3.x used `import fetch from 'native-fetch'` (default export), but v4 switched to named export.
fix
Change default import to named import: `import { fetch } from 'native-fetch'`
affects: <4.0.0
Errors
Common errors & fixes
Cannot find module 'native-fetch'
The package is not installed or missing peer dependency undici.
fix
Run `npm install native-fetch undici`
import { fetch } from 'native-fetch'; SyntaxError: Cannot use import statement outside a module
The project is not configured for ESM (e.g., missing "type": "module" in package.json).
fix
Add "type": "module" to your package.json or use .mjs extension.
The module 'native-fetch' has no exported member 'fetch'.
Using an outdated version (<4.0.0) that exports fetch as default.
fix
Update to v4: `npm install native-fetch@latest`
TypeError: fetch is not a function
Importing the module incorrectly (e.g., `const nativeFetch = require('native-fetch')` and then calling `nativeFetch()` instead of `nativeFetch.fetch()`).
fix
Use named import: `import { fetch } from 'native-fetch'`
Upgrade
Version history
4.0.2latest on npm
Audit
Dependencies
undicirequiredPeer dependency used as fallback when native fetch is not available
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
native-fetch — npm install native-fetch · libregistry