node-tld
node-tld copied to clipboard
Cannot read property 'split' of null
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)
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.
This is not an issue if you ask @131 see https://github.com/131/node-tld/issues/7
@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