`pac-proxy-agent` is a Node.js module that provides an `http.Agent` implementation for resolving proxy settings using a Proxy Auto-Configuration (PAC) file. It is part of the actively maintained `proxy-agents` monorepo by TooTallNate and is currently at version `9.0.1`. This agent seamlessly integrates with Node.js's native `http` and `https` modules, automatically determining whether to use a direct connection, an HTTP proxy, an HTTPS proxy, or a SOCKS proxy based on the PAC file's logic for a given target URL. Releases typically follow the monorepo's cadence, often aligning major version bumps with Node.js LTS updates, such as the recent shift to Node.js 20. Its key differentiator is its robust and secure PAC file interpretation, leveraging `quickjs-wasi` for isolated PAC script execution.
npm install pac-proxy-agentVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing `PacProxyAgent` with a PAC file URL and using it with Node.js's built-in `http.get`.
Upgrade your Node.js environment to version 20 or newer. Consider using a Node.js version manager like `nvm`.
Convert your module to ESM by using `import` statements and ensuring your `package.json` has `"type": "module"` or that your file uses a `.mjs` extension. This change is directly related to the Node.js 20 minimum requirement.
Validate your PAC file syntax using a linter or online tool. Ensure the PAC file URL is always reachable and returns a valid JavaScript. Implement robust error handling around connections when using the agent.
Ensure you are on `pac-proxy-agent` v9.0.1 or newer to benefit from these stability improvements. No direct code changes are typically required unless you're interacting with `pac-resolver` directly.
Convert your module to use ECMAScript `import` statements. For CommonJS projects, consider using dynamic `import()` or upgrading your project to `type: "module"` in `package.json` and ensure Node.js >= 20.
Ensure you are using `import { PacProxyAgent } from 'pac-proxy-agent';` and that your Node.js environment is version 20 or newer, configured for ESM. If dynamically importing in a CommonJS module, use `import('pac-proxy-agent').then(m => new m.PacProxyAgent(...))`.Upgrade your Node.js environment to version 20 or newer. Tools like `nvm` (Node Version Manager) can help manage multiple Node.js versions on your system.