FredKSchott / rollup-plugin-polyfill-node

A modern Node.js polyfill for your Rollup bundle.
Other
179 stars 57 forks source link

Error: "urlToHttpOptions" is not exported by "polyfill-node.url.js" #80

Open Carloss616 opened 7 months ago

Carloss616 commented 7 months ago

I'm using 0.13.0 and seeing this error when I bundle.

[!] Error: "urlToHttpOptions" is not exported by "polyfill-node.url.js".
 9: import { URL, urlToHttpOptions } from 'url';
                  ^

I'd like to submit a PR to resolve this problem soon or you can help me with it. I found that we can use the following:

function urlToHttpOptions(url) {
  const options = {
    protocol: url.protocol,
    hostname: typeof url.hostname === 'string' &&
              String.prototype.startsWith.call(url.hostname, '[') ?
      String.prototype.slice.call(url.hostname, 1, -1) :
      url.hostname,
    hash: url.hash,
    search: url.search,
    pathname: url.pathname,
    path: `${url.pathname || ''}${url.search || ''}`,
    href: url.href
  };
  if (url.port !== '') {
    options.port = Number(url.port);
  }
  if (url.username || url.password) {
    options.auth = `${url.username}:${url.password}`;
  }
  return options;
};

Source code: https://github.com/szmarczak/http2-wrapper/issues/73#issuecomment-878502661