Isomorphic-fetch is a JavaScript library that provides the WHATWG Fetch API for both Node.js and browser environments. Its current stable version is 3.0.0. The package operates as a polyfill, meaning it modifies the global scope to add the `fetch` function and related constructs like `Headers`, `Request`, and `Response`. For server-side operations, it leverages `node-fetch`, while for client-side, it's built on GitHub's WHATWG Fetch polyfill. Its release cadence has slowed, with the last major version (v3.0.0) released significantly after previous iterations, suggesting a maintenance rather than active development phase. A key differentiator is its polyfill approach, which automatically makes `fetch` available globally, contrasting with 'ponyfill' alternatives like `fetch-ponyfill` or `cross-fetch` that avoid global pollution. This design choice aims for API consistency but requires users to be aware of global modifications.
npm install isomorphic-fetchVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage by performing a GET request to an API, handling the response, and logging data or errors.
Be mindful of the import order. If global pollution is a concern, consider alternatives like `fetch-ponyfill` or `cross-fetch` which provide the API without modifying the global scope.
If specific polyfill behavior is required, ensure it loads before any native `fetch` or other polyfills. If a specific version of `fetch` is needed, consider importing `node-fetch` or `github/fetch` directly and managing their scope.
Thoroughly test server-side fetch requests when upgrading from versions prior to 2.0.0. Review `node-fetch` documentation for any specific behaviors you might have relied on in the previous implementation.
Ensure `require('isomorphic-fetch');` is placed at the very top of your application's main entry file or within any module that intends to use the global `fetch`. Alternatively, import the `fetch` function directly using `const fetch = require('isomorphic-fetch');`.Verify that `require('isomorphic-fetch');` has executed. If you need to access `Headers`, `Request`, or `Response` explicitly, import them using named CJS destructuring: `const { Headers, Request, Response } = require('isomorphic-fetch');`.No dependency data recorded yet.