Registry / testing / fetch-jsonp-polyfill

fetch-jsonp-polyfill

JSON →
library1.1.5jsnpmunverified

A polyfill that adds JSONP support to the Fetch API by allowing method: 'JSONP' in fetch options. Current stable version is 1.1.5 (not updated since 2016). It wraps existing fetch polyfills like github/fetch, isomorphic-fetch, or node-fetch and must be imported after them. Unlike alternatives, it does not expose a separate JSONP function but monkey-patches the global fetch to transparently handle JSONP requests when the method is set to 'JSONP'. Supports common JSONP options: timeout, callback query parameter name, and callback function name.

npm install fetch-jsonp-polyfill
INSTALL
IMPORT
SIG · FETCH-JSONP-POLYFI
F
fetch-jsonp-polyfill
testingjavascriptv1.1.5
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-jsonp-polyfill (side-effect import)
import 'fetch-jsonp-polyfill'
import fetchJsonp from 'fetch-jsonp-polyfill'
This package is a side-effect polyfill that modifies the global fetch. It does not export any symbols.
require (CommonJS)
require('fetch-jsonp-polyfill')
const fetchJsonp = require('fetch-jsonp-polyfill')
In CommonJS, assign the require to a variable is misleading because no value is exported. Just call require without assignment.
import order
import 'isomorphic-fetch'; import 'fetch-jsonp-polyfill'
import 'fetch-jsonp-polyfill'; import 'isomorphic-fetch'
Must import the base fetch polyfill (e.g., isomorphic-fetch) before this polyfill, otherwise JSONP requests will fail.

Shows how to use the polyfill: import after a base fetch polyfill, then call fetch with method:'JSONP' and optional JSONP-specific options.

// Install: npm install fetch-jsonp-polyfill isomorphic-fetch import 'isomorphic-fetch'; import 'fetch-jsonp-polyfill'; const URL = 'http://jsfiddle.net/echo/jsonp/'; fetch(URL, { method: 'JSONP', timeout: 5000, callback: 'callback', callbackName: 'fetchjsonp_callback' }) .then(res => res.json()) .then(data => { console.log('JSONP response:', data); }) .catch(err => { console.error('JSONP error:', err); });
Debug
Known issues
deprecatedThe package has not been updated since 2016 and is effectively deprecated. Use without active maintenance.
fix
Consider using a maintained solution like fetch-jsonp (npm package 'fetch-jsonp') which exports a standalone function.
affects: >=1.0.0
breakingGlobal fetch polyfill must be imported BEFORE fetch-jsonp-polyfill, otherwise fetch may be undefined or lack polyfill methods.
fix
Ensure any fetch polyfill (e.g., isomorphic-fetch, whatwg-fetch) is imported first.
affects: >=1.0.0
gotchaUsing method:'JSONP' will cause CORS-like preflight errors if the server does not support JSONP. JSONP is inherently insecure (XSS vector) and only uses GET.
fix
Only use JSONP with trusted third-party APIs; prefer CORS-enabled endpoints and standard fetch.
affects: >=1.0.0
gotchaThe polyfill modifies global fetch. In Node.js environment, node-fetch must be polyfilled first.
fix
If using in Node, install and import node-fetch before this polyfill. Read README for compatible polyfills.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: fetch is not a function
Missing a base fetch polyfill (e.g., isomorphic-fetch) or import order reversed.
fix
Install and import a fetch polyfill before fetch-jsonp-polyfill: import 'isomorphic-fetch'; import 'fetch-jsonp-polyfill';
fetch(...).then(res => res.json()) is not a function
JSONP response is not standard JSON but wrapped in a function call; the polyfill does not unwrap it.
fix
You may need to parse the response manually or use a different library that handles JSONP response extraction.
Upgrade
Version history
1.1.5latest on npm
Audit
Dependencies
whatwg-fetchrequiredSuggested as a base fetch polyfill for browser environments; fetch-jsonp-polyfill depends on a global fetch implementation.
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-jsonp-polyfill — npm install fetch-jsonp-polyfill · libregistry