Registry / testing / react-native-fetch-polyfill

react-native-fetch-polyfill

JSON →
library1.1.3jsnpmunverified

A polyfill for React Native's fetch that adds timeout support. Currently at version 1.1.3 (stable, low release cadence). It patches the default fetch implementation from whatwg-fetch to expose the native XMLHttpRequest timeout property, which is otherwise inaccessible. Unlike alternatives like react-native-fetch-api or custom wrappers, this polyfill directly modifies the global fetch, providing seamless integration. Requires react-native >=0.27.

npm install react-native-fetch-polyfill
INSTALL
IMPORT
SIG · REACT-NATIVE-FETCH
R
react-native-fetch-polyfill
testingjavascriptv1.1.3
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 'react-native-fetch-polyfill';
import { fetch } from 'react-native-fetch-polyfill';
The module exports a default fetch function, not a named export. CommonJS require works: const fetch = require('react-native-fetch-polyfill');
fetch as global override
import fetch from 'react-native-fetch-polyfill'; // Will polyfill global fetch automatically if used before other fetch calls.
Global fetch is not automatically replaced; you must explicitly import the polyfill and use the returned fetch function.
The polyfill does not modify global fetch; you must assign it yourself if you want global usage.
TypeScript type
import fetch from 'react-native-fetch-polyfill'; // No types provided; you may need to declare module or use @types/react-native-fetch-polyfill if available.
Not a mistake, but type definitions are missing. Cast to any or install @types.
Package has no TypeScript types. For type safety, create a declaration file or use a custom wrapper.

Demonstrates importing the polyfill and using the timeout option in a fetch request with error handling for timeouts.

import fetch from 'react-native-fetch-polyfill'; const url = 'https://api.example.com/data'; const options = { method: 'GET', headers: { 'Accept': 'application/json' }, timeout: 30000, // 30 seconds }; fetch(url, options) .then(response => response.json()) .then(data => console.log(data)) .catch(error => { if (error.name === 'AbortError') { console.log('Request timed out'); } else { console.log('Fetch error:', error); } });
Debug
Known issues
gotchaThe polyfill does NOT automatically override the global fetch; you must import and call the returned fetch explicitly.
fix
Import the polyfill and assign it: import fetch from 'react-native-fetch-polyfill'; then use fetch(...) instead of global fetch.
affects: >=1.0.0
gotchaTimeout option is only supported for React Native's native networking; it will not work in environments like Expo's managed workflow unless you eject.
fix
If using Expo managed, consider using the AbortController polyfill or a custom timeout implementation.
affects: >=1.0.0
deprecatedPackage is in maintenance mode; no active development since 2017. Consider using react-native-fetch-api or AbortController for modern timeout support.
fix
Upgrade to react-native-fetch-api or use the AbortController polyfill (available in React Native 0.50+).
affects: >=1.0.0
gotchaThe polyfill patches internal functions of whatwg-fetch; may break if React Native updates its fetch implementation.
fix
Test after RN upgrades; check for compatibility issues.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Network request failed
The timeout was reached and the native layer rejected the request with a generic network error.
fix
Handle the error by checking for a timeout: if (error.message === 'Network request failed') { /* timeout logic */ }
undefined is not an object (evaluating 'fetch.timeout')
Trying to access the timeout property on the fetch function, but the polyfill expects the timeout in the options object.
fix
Pass timeout as part of the second argument (options): fetch(url, { timeout: 10000 })
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
react-nativerequiredPeer dependency; polyfill relies on React Native's networking module (RCTNetworking).
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
react-native-fetch-polyfill — npm install react-native-fetch-polyfill · libregistry