FredKSchott / FredKSchott/rollup-plugin-polyfill-node

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

Open
#80 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
193
Forks
60
PR merge metrics
No merged PRs in 30d

Description

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

```bash
[!] 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:

```js
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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.