question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Uncaught error: "TypeError [ERR_INVALID_URL]: Invalid URL: https://"

See original GitHub issue

Uncaught error: TypeError [ERR_INVALID_URL]: Invalid URL: https://

Reproduction

See the PoC

const Koa = require("koa");
const fetch = require("node-fetch");

const app = new Koa();

app.use(async ctx => {
  ctx.set("Location", "https://");
  ctx.status = 301;
});

app.listen(3000);

(async () => {
  try {
    await fetch("http://localhost:3000");
  } catch (error) {
    console.log("catch");
  }
  console.log("done");
})();

Expected behavior

The PoC should print:

catch
done

Actual behavior

The PoC prints:

internal/url.js:257
  throw new ERR_INVALID_URL(input);
  ^

TypeError [ERR_INVALID_URL]: Invalid URL: https://
    at onParseError (internal/url.js:257:9)
    at new URL (internal/url.js:333:5)
    at ClientRequest.<anonymous> (/home/runner/UnfoldedShockingLocus/node_modules/node-fetch/dist/index.cjs:1291:52)
    at ClientRequest.emit (events.js:310:20)
    at ClientRequest.EventEmitter.emit (domain.js:482:12)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:596:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
    at Socket.socketOnData (_http_client.js:469:22)
    at Socket.emit (events.js:310:20)
    at Socket.EventEmitter.emit (domain.js:482:12) {
  input: 'https://',
  code: 'ERR_INVALID_URL'
}

Your Environment

software version
node-fetch 3.0.0-beta.7
node 12.16.3
npm 6.14.4
Operating System Linux

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
JefferyHuscommented, Jun 30, 2020

Ok, now it makes sense. If you just described it same way in your issue.

0reactions
jimmywartingcommented, Jan 22, 2022

this have been fixed with a try/catch and manual no longer throws for those who wish to manually handle wrong urls in the location header

Read more comments on GitHub >

github_iconTop Results From Across the Web

mongodb - TypeError [ERR_INVALID_URL]: Invalid URL
I got below error. I am new to nestjs. Please help me to find the error TypeError [ERR_INVALID_URL]: Invalid URL ...
Read more >
Uncaught error: "TypeError [ERR_INVALID_URL]: Invalid ...
Bug : Uncaught error: "TypeError [ERR_INVALID_URL]: Invalid URL: https://"
Read more >
Node.js Client TypeError [ERR_INVALID_URL]: Invalid URL
Hello, I am trying to deploy a 1Password Connect Server via Docker as per your instructions but, I am getting the following error...
Read more >
Concerning error "Invalid URL" - Bug Reports
I tried opening the dev tools (ctrl-shift-i) but there were no errors reported on the console. [Main Exception] Invalid URL TypeError [ ...
Read more >
TypeError: Failed to construct 'URL': Invalid URL (Example)
Hello, I'm attempting to use images and videos in my react component and I'm receiving one of two errors. Where I try the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found