TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
917 stars 238 forks source link

After 7.0.3 Update: node:url Module build failed: UnhandledSchemeError: Reading from "node:url" is not handled by plugins #287

Closed SolidAnonDev closed 7 months ago

SolidAnonDev commented 7 months ago

I am utilizing Next.JS with next-auth, and unfortunately have to apply a patch to the next-auth package due to use behind a corporate proxy, a tutorial for which is outlined here.

I'll paste the code here for reference as well:

var _openidClient = require("openid-client");
var proxyAgent = require("https-proxy-agent");
async function openidClient(options) {
  const provider = options.provider;
  let httpOptions = {};
  if (provider.httpOptions) httpOptions = { ...provider.httpOptions };
  if (process.env.http_proxy) {
      let agent = new proxyAgent.HttpsProxyAgent(process.env.http_proxy); // problematic line
      httpOptions.agent = agent;
    }
   // rest of the function
}

This was and has been working fine until the recent 7.0.3 release, in which I actually can't get any of my routes to load due to the above usage of https proxy agent because of the following error:

node:url Module build failed: UnhandledSchemeError: Reading from "node:url" is not handled by plugins 
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.

Unfortunately reproducing this would be kind of difficult, but if one really wanted to you'd have to set up next-auth in a next.js project with this https-proxy-agent utilizing linked patch, and this particular piece of code specifically relates to using Microsoft Entra Id for Oauth Sign in.

I can downgrade to 7.0.2 and all is well. If there's something I can change in my code I'm happy to do so, but It's not readily apparent to me what happened.

TooTallNate commented 7 months ago

You'll need to update webpack or one of the related plugins. node:url is a valid import.