-
Notifications
You must be signed in to change notification settings - Fork 314
Description
What version of PnPjs library you are using
4.x
Minor Version Number
4.14.0
Target environment
NodeJS
Additional environment details
- Node.js v22 backend
- Proxy required for internet access
- Custom token provider using MSAL (already working)
- Proxy setup using https-proxy-agent
Question/Request
Hi all! 👋 We’re using @pnp/pnpjs in a Node.js backend environment, which requires a proxy to access external services like Microsoft Graph and SharePoint APIs.
We were happy to find the proxy configuration example in the documentation, and implemented it using the same https-proxy-agent that we already use successfully for other connections. However, upon testing, we started encountering network-related errors (ENOTFOUND) when making requests to the Graph API.
After some investigation, we discovered that the proxy example relies on configuring the HTTPS agent in the native fetch implementation. However, the native Node.js fetch API does not support custom agent configuration.
See: https://stackoverflow.com/questions/72306101/make-a-request-in-native-fetch-with-proxy-in-nodejs-18
The workaround: We resolved the issue by re-implementing the NodeFetchWithRetry behavior using the node-fetch package, as it was done previously: 3cf4c77
At this point, i'm not sure if going back to node-fetch makes sense:
- Node.js >= 24 is expected to support proxy configuration via environment variables with native fetch (may 2025 🙃)
- Node.js >= 18 It might make sense to revert to node-fetch for now, at least until Node.js 24 is widely adopted.
- MSALjs has a very similar issue with proxies, so even fixing the proxy behavior example, will require additional steps to make pnpjs node package to work behind proxy.
It would be nice to have a little feedback on this...