Registry / testing / abortcontroller-polyfill

abortcontroller-polyfill

JSON →
library1.7.8jsnpmunverified

Polyfill for the AbortController DOM API, enabling abortable fetch() in browsers that don't yet support it. Current version is 1.7.8 (last release June 2022, low maintenance). It doesn't actually cancel the underlying network request but simulates abort behavior by rejecting the promise with an AbortError. Can also polyfill AbortController/AbortSignal alone without patching fetch. Supports both browser and Node.js usage via CJS or ESM imports. Alternative to using native AbortController or other polyfills like abort-controller.

npm install abortcontroller-polyfill
INSTALL
IMPORT
SIG · ABORTCONTROLLER-PO
A
abortcontroller-polyfill
testingjavascriptv1.7.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.

polyfill (global)
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
import AbortController from 'abortcontroller-polyfill'
Default import is not available; use side-effect import for global polyfill.
AbortController (ponyfill)
import { AbortController } from 'abortcontroller-polyfill/dist/cjs-ponyfill'
import { AbortController } from 'abortcontroller-polyfill'
The main package only exports via dist subpath. CJS ponyfill path is needed for named exports.
CommonJS require (ponyfill)
const { AbortController, abortableFetch } = require('abortcontroller-polyfill/dist/cjs-ponyfill')
const abortcontrollerPolyfill = require('abortcontroller-polyfill')
Wrong: does not import ponyfill. Must use specific dist path.
TypeScript types
import { AbortController } from 'abortcontroller-polyfill/dist/cjs-ponyfill'
import { AbortController } from 'abortcontroller-polyfill'
This package ships TypeScript declarations only for the ponyfill subpath. Importing from main fails.

Shows browser-side import of polyfill patching fetch, and Node.js ponyfill usage with node-fetch. Demonstrates AbortController creation, signal passing, and abort handling.

// Browser: import side-effect polyfill with fetch patching import 'abortcontroller-polyfill/dist/polyfill-patch-fetch' const controller = new AbortController(); const signal = controller.signal; fetch('https://api.example.com/data', { signal }) .then(response => response.json()) .then(data => console.log(data)) .catch(err => { if (err.name === 'AbortError') { console.log('Fetch aborted'); } }); // Later, trigger abort: // controller.abort(); // Node.js: ponyfill with node-fetch const { AbortController, abortableFetch } = require('abortcontroller-polyfill/dist/cjs-ponyfill'); const nodeFetch = require('node-fetch'); const { fetch } = abortableFetch(nodeFetch); async function main() { const controller = new AbortController(); setTimeout(() => controller.abort(), 100); try { const res = await fetch('https://example.com', { signal: controller.signal }); console.log(await res.text()); } catch (err) { if (err.name === 'AbortError') console.log('Aborted'); } } main();
Debug
Known issues
gotchaPolyfill does not actually abort the underlying network request; only rejects promise with AbortError.
fix
Understand that the request continues server-side. Use native AbortController when available for true cancellation.
affects: >=1.0.0
gotchaPackage is in maintenance mode with no recent updates. No support for newer fetch features like ReadableStream cancellation.
fix
Consider using native AbortController (Node 15+) or other actively maintained polyfills.
affects: >=1.0.0
deprecatedCJS ponyfill import path may change in future; currently requires full dist path.
fix
Always import from 'abortcontroller-polyfill/dist/cjs-ponyfill' when using named exports.
affects: =1.7.8
gotchaWhen using with create-react-app, eslint may throw no-undef on AbortController. Requires window.AbortController declaration.
fix
Add /* global AbortController */ or use window.AbortController in code.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'abortcontroller-polyfill'
Importing from main package instead of dist subpath when using named exports.
fix
Change import to 'abortcontroller-polyfill/dist/cjs-ponyfill' or use side-effect import.
'AbortController' is not defined no-undef
ESLint not recognizing AbortController as global in browser environment.
fix
Add '/* global AbortController */' at top of file or set eslint-env browser.
Failed to fetch (no actual abort)
Expecting the polyfill to cancel the network request, but it only rejects promise.
fix
Use native AbortController for true cancellation, or adjust expectations.
Upgrade
Version history
1.7.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
40
OpenAI (training)
1
Resources
abortcontroller-polyfill — npm install abortcontroller-polyfill · libregistry