nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.69k stars 29.64k forks source link

url.Url shows up in the repl but only url.URL should be showing up #44904

Closed govindrai closed 2 years ago

govindrai commented 2 years ago

Version

v17.3.0

Platform

Darwin GRai-M-T576V 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 x86_64

Subsystem

No response

What steps will reproduce the bug?

Head into the node repl

❯ node
Welcome to Node.js v17.3.0.
Type ".help" for more information.
> const url = require("url")
undefined
> const myUrl = url.Url("https://abc.com?queryParam=a&otherQueryParam=b")
undefined
> myUrl
undefined
> typeof myUrl
'undefined'

How often does it reproduce? Is there a required condition?

100%

What is the expected behavior?

I expect url.Url() to not be an available method since it'd not in the documentation and produces a TS error when trying to use it in an editor such as VS Code

What do you see instead?

image

Additional information

This is a bit pernicious because I spent a while trying to figure out why my url wasn't returning anything even though it seemed as if I was apparently following node tutorials properly, not seeing the incorrect case (I needed to use url.URL vs url.Url).

mscdex commented 2 years ago

It is documented here. It's part of the "legacy" url functionality.

aduh95 commented 2 years ago

URL is available as a global if that helps, you don't need to require('node:url'):

$ node
Welcome to Node.js v18.9.0.
Type ".help" for more information.
> const myUrl = new URL("https://abc.com?queryParam=a&otherQueryParam=b")
undefined
> myUrl
URL { … }
> typeof myUrl
'object'

I'm not sure what can be done here, url.Url cannot be removed as it could break the ecosystem. I suggest we close this as "Won't fix" for now, but let me know if you see a way to improve the situation (or feel free to ask more questions if you have any).