Registry /
testing / abortcontroller-polyfill
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();
Errors
Common errors & fixes
Cannot find module 'abortcontroller-polyfill'
Importing from main package instead of dist subpath when using named exports.
fixChange 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.
fixAdd '/* 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.
fixUse native AbortController for true cancellation, or adjust expectations.
Audit
Dependencies
No dependency data recorded yet.