Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Invalid URL #1342

Closed
tyanbiao opened this issue Oct 21, 2021 · 3 comments
Closed

TypeError: Invalid URL #1342

tyanbiao opened this issue Oct 21, 2021 · 3 comments
Labels

Comments

@tyanbiao
Copy link

Reproduction

Steps to reproduce the behavior:

  1. use node-fetch to request url https://r2---sn-n4v7sney.googlevideo.com
  2. throw error: TypeError: Invalid URL

You can try to reproduce the issue by running the code below

const fetch = require('node-fetch')

async function getAudio() {
    const ret = await fetch('https://r2---sn-n4v7sney.googlevideo.com')
    const text = await ret.text()
    return text
}

getAudio().catch(e => console.error(e))

Expected behavior

https://r2---sn-n4v7sney.googlevideo.com is a valid url

Screenshots

temp

Your Environment

software version
node-fetch 2.6.5
node v14.18.1
npm 6.14.15
Operating System Windows 10

Additional context

@tyanbiao tyanbiao added the bug label Oct 21, 2021
@jimmywarting
Copy link
Collaborator

This boils down to:

const whatwg = require('whatwg-url@5')
new whatwg.URL('https://r2---sn-n4v7sney.googlevideo.com') // throws not valid url error

using:

const whatwg = require('whatwg-url@latest')
new whatwg.URL('https://r2---sn-n4v7sney.googlevideo.com') // works fine
new globalThis.URL('https://r2---sn-n4v7sney.googlevideo.com') // also works fine

And we could not use the latest whatwg-url version since v2 still supports node v4
using a older whatwg-url is by no doubt buggy...

Maybe we could rely on the built in node version if available and then fallback to whatwg if it's not available?

changing this to: require('url').URL || whatwgUrl.URL

const URL = whatwgUrl.URL;

This will not actually fix the issue for older node versions, only hide it in newer node versions...


fyi, v3 don't have this issue cuz it uses nodes own URL

@jimmywarting
Copy link
Collaborator

could you try 2.6.6 if it works now?

@tyanbiao
Copy link
Author

tyanbiao commented Nov 3, 2021

could you try 2.6.6 if it works now?

It works fine in version 2.6.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants