rollup-plugin-polyfill-node
rollup-plugin-polyfill-node copied to clipboard
Error: "urlToHttpOptions" is not exported by "polyfill-node.url.js"
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