Registry / devops / taro-fetch-polyfill

taro-fetch-polyfill

JSON →
library0.5.8jsnpmunverified

W3C fetch() API polyfill for Taro 3+ miniapp frameworks. Current stable version is 0.5.8. Provides a ponyfill that works around the locked global object in miniapps, allowing developers to use the standard fetch() interface instead of Taro's native request API. Ships TypeScript types. Updated infrequently.

npm install taro-fetch-polyfill
INSTALL
IMPORT
SIG · TARO-FETCH-POLYFIL
T
taro-fetch-polyfill
devopsjavascriptv0.5.8
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 'taro-fetch-polyfill'
import fetch from 'taro-fetch-polyfill'
Named import only; default export does not exist.
Request
import { Request } from 'taro-fetch-polyfill'
const Request = require('taro-fetch-polyfill').Request
ESM import works; CJS require also works but named import is preferred.
Response
import { Response } from 'taro-fetch-polyfill'
Same as Request; named import is correct.
Headers
import { Headers } from 'taro-fetch-polyfill'
Same as Request; named import is correct.

Shows basic fetch usage with JSON parsing and error handling.

import { fetch } from 'taro-fetch-polyfill'; fetch('https://api.github.com') .then(response => response.json()) .then(console.log) .catch(err => console.error(err));
Debug
Known issues
gotchaCannot polyfill globally because miniapps lock the global object. Use ponyfill imports only.
fix
Import { fetch } from the package instead of expecting window.fetch or globalThis.fetch.
affects: >=0.0.0
gotchafetch behavior may not fully match browser Fetch API; limited by miniapp runtime capabilities.
fix
Test thoroughly; some features like streaming or abort may not work.
affects: >=0.0.0
deprecatedPackage is unmaintained; no updates since 2021.
fix
Consider alternatives or fork the project.
affects: >=0.5.8
Errors
Common errors & fixes
import { fetch } from 'taro-fetch-polyfill'; TypeError: Cannot read properties of undefined (reading 'fetch')
Using default import instead of named import.
fix
Use named import: import { fetch } from 'taro-fetch-polyfill';
ReferenceError: fetch is not defined
Trying to use fetch globally via polyfill; miniapps don't support global polyfill.
fix
Import fetch as a ponyfill: import { fetch } from 'taro-fetch-polyfill'; then call fetch() directly.
Module not found: Can't resolve 'taro-fetch-polyfill'
Package not installed or missing peer dependency @tarojs/taro.
fix
Install the package and its peer dependency: npm install taro-fetch-polyfill @tarojs/taro
Upgrade
Version history
0.5.8latest on npm
Audit
Dependencies
@tarojs/tarorequiredRequired peer dependency for version 3+
Agent activity
10 hits · last 30 days
node
8
Resources
taro-fetch-polyfill — npm install taro-fetch-polyfill · libregistry