Tracking Issue: Legacy URL deprecation #23694
Replies
|
Hi, const url = new URL("http://example.com");
url.protocol = "https";
url.toString(); // --> 'https://example.com/'Using the legacy API it is possible to construct an url with url.format. What is the way to do this going forward? Using a dummy url to be allowed to create a URL object seems like a hack but will probably be easier than taking in an extra npm package to implement it. Or have I completely missed how to do this in the docs? :) Thank you for your time, |
|
Thank you for the response! Seems like pretty easy solutions but still a bit hackish to have to enter a dummy url. Would it be possible to remove the requirement for giving an initial url or would that break the spec? |
Seems like either:
|
|
|
As it is related I wanted to mention the suggestion at whatwg/url#421 for URL.relative, which can always be done in Node without a URL spec. If more people show interest now it could be worthwhile to line up though. |
|
I'm hoping we might have just published something that helps with this. @janicklas-ralph put a bunch of time into porting (in spirit) Node's It contains a number of fixes for the cases noted by @l1bbcsg and others elsewhere. |
|
Hey, this was working with legacy url
This throws a type error
What to do ? |
|
The WHATWG URL parser does not work with relative URL without specifying a base. We cannot deviate from that as it's mandated by the standard. The way to address this is: |


The legacy url API (
url.parse(),url.format(), andurl.resolve()) have been docs-only deprecated.Following the Node.js 11.0.0 release, I plan to open a PR that upgrades that to a pending runtime-deprecation (requires
--pending-deprecationfor the warning to appear). That would land in master but would not go into a release until 12.0.0 (April 2019)Following the 12.0.0 release, I plan to on a PR that upgrades that to a full run-time deprecation that would last in master but would not go into a release until 13.0.0 (October 2019).
After the 13.0.0 release, I would like to move the legacy url API to End-of-Life, allowing us to remove it.
To support existing code that is still using the legacy URL, the implementation can be moved into a separate standalone module published on npm (similar to the existing
node-urlmodule).