node-fetch-native-with-agent is a fork of node-fetch-native that provides a universal `fetch` implementation for Node.js, designed for compatibility across various Node.js versions and environments. It intelligently prefers the native `fetch` global (backed by Undici) when available in newer Node.js versions and falls back to a bundled `node-fetch v3` implementation for older versions, all while supporting both CommonJS (`require`) and ESM (`import`). Its key differentiator is the compact size, zero direct dependencies for the core, and robust built-in proxy support via custom agents, which is a common challenge with native `fetch` in Node.js. The current stable version is 1.7.2, with minor fixes released as needed, indicating an active maintenance cadence. It also includes polyfill capabilities to make `fetch` globally available. This package aims to solve the `node-fetch` v2 vs v3 dependency conflicts and the lack of straightforward proxy support with Node.js's native `fetch`.
npm install node-fetch-native-with-agentVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic `fetch` usage with `node-fetch-native-with-agent`, including how to configure and use an `HttpsProxyAgent` for HTTP/S proxy support. It explicitly shows agent creation, although the library also respects `HTTP_PROXY`/`HTTPS_PROXY` environment variables automatically.
For CommonJS, use `const fetch = require('node-fetch-native-with-agent');` directly. For named exports, use `const { fetch, Headers } = require('node-fetch-native-with-agent');`.To force the use of the non-native `node-fetch` implementation, either set the environment variable `FORCE_NODE_FETCH=1` or import from `node-fetch-native-with-agent/node` (e.g., `import fetch from 'node-fetch-native-with-agent/node';`).
Prefer explicit imports of `fetch` (e.g., `import fetch from 'node-fetch-native-with-agent';`) within your modules rather than relying on global polyfilling, especially when authoring libraries.
Verify that `HTTP_PROXY` or `HTTPS_PROXY` (or their lowercase counterparts) environment variables are correctly set before application startup. If passing a custom agent, ensure it's compatible and correctly instantiated (e.g., `new HttpsProxyAgent(proxyUrl)`).
If in CommonJS, use `const fetch = require('node-fetch-native-with-agent');`. If using a bundler, ensure it correctly handles CommonJS to ESM interop or configure it to resolve `node-fetch-native-with-agent` correctly for your target environment.Ensure you are using a compatible proxy agent like `https-proxy-agent` or allowing `node-fetch-native-with-agent` to handle proxy setup automatically via environment variables. The package is specifically built to bridge this gap.
Either import `fetch` explicitly (`import fetch from 'node-fetch-native-with-agent';`) or import the polyfill to make it globally available (`import 'node-fetch-native-with-agent/polyfill';`). Ensure the import statement runs before `fetch` is called.
No dependency data recorded yet.