Skip to content

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

@Carloss616

Description

@Carloss616

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: szmarczak/http2-wrapper#73 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions