Skip to content

TypeError: Invalid URL #1342

Closed
Closed

Description

@tyanbiao

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

Activity

  1. jimmywarting commented on Oct 21, 2021

    @jimmywarting
    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

  2. jimmywarting commented on Oct 31, 2021

    @jimmywarting
    Collaborator

    could you try 2.6.6 if it works now?

  3. tyanbiao commented on Nov 3, 2021

    @tyanbiao
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions