node-tld icon indicating copy to clipboard operation
node-tld copied to clipboard

Cannot read property 'split' of null

Open sauravkoli31 opened this issue 4 years ago • 3 comments

receiving the following error while trying parser("www.google.com")

TypeError: Cannot read property 'split' of null
    at parse_host (\node_modules\tld-extract\index.js:23:20)
    at parse_url (\node_modules\tld-extract\index.js:9:10)

sauravkoli31 avatar Mar 08 '21 22:03 sauravkoli31

Issue seems to be with the url package dependency. url.parse has been deprecated.

function parse(urlStr: string): url.UrlWithStringQuery (+3 overloads)
@deprecated — since v11.0.0 - Use the WHATWG URL API.

The signature '(urlStr: string): UrlWithStringQuery' of 'url.parse' is deprecated.ts(6387)
url.d.ts(47, 9): The declaration was marked as deprecated here.

sauravkoli31 avatar Mar 08 '21 22:03 sauravkoli31

This is not an issue if you ask @131 see https://github.com/131/node-tld/issues/7

leptoquark1 avatar Mar 25 '21 09:03 leptoquark1

@sauravkoli31 Even if the url.parse is now deprecated and even if the library is updated to use new URL('...'), you will still have the same issue.

You just need to use the parse_host function instead. Just like @leptoquark1 suggested.

The API is:

import parse_url, { parse_host } from 'tld-extract';

parse_url('https://www.google.com') // this requires the full URL including the protocol
parse_host('www.google.com') // expects to parse just the hostname of a URL

mfpopa avatar Jun 06 '21 07:06 mfpopa