defunctzombie / node-url

node.js core url module as a module
MIT License
375 stars 96 forks source link

[bug] URL is not a constructor #37

Open webpack-bot opened 7 years ago

webpack-bot commented 7 years ago

Do you want to request a feature or report a bug?

Bug with WHATWG URL API provided by native url module.

What is the current behavior?

// ES6

import { URL } from 'url';

console.log(typeof URL); // undefined
// CommonJS

const { URL } = require('url');

console.log(typeof URL); // undefined

If the current behavior is a bug, please provide the steps to reproduce. I provided code above, is it a normal behavior and we should use Web API URL or WHATWG URL API should be provided through url module?

What is the expected behavior?

// ES6 modules

import { URL } from 'url';

console.log(typeof URL); // function
// CommonJS modules

const { URL } = require('url');

console.log(typeof URL); // function

Please mention your webpack and Operating System version.

node 8.2.1 webpack 3.3.0 macOS Sierra 10.12.6


This issue was moved from webpack/webpack#5372 by @sokra. Orginal issue was by @zalishchuk.

node-url exports it as exports.Url instead of exports.URL

mightyiam commented 6 years ago

It seems an eco-system winner is the url-parse package.

davydof commented 5 years ago

any update?

redbrain commented 3 years ago

Having this issue on a production app. A fix would be nice to see. Mentioning @defunctzombie because they're the only clear maintainer.

defunctzombie commented 3 years ago

I don't maintain this module anymore.

ljharb commented 3 years ago

@defunctzombie i'd be happy to take it over, if only to clear up issues like this.

defunctzombie commented 3 years ago

I've added @ljharb you as a collaborator.

ljharb commented 3 years ago

@defunctzombie thanks! if you want to npm owner add ljharb, that'd be great. Also, if you wanted to transfer this into the browserify org, that would ensure there's not a single point of failure anywhere :-)

defunctzombie commented 3 years ago

@ljharb I've added you as the owner on npm.

ljharb commented 3 years ago

I'll address this as part of the "node catchup" described in #53.

Lazauya commented 2 years ago

It seems like the solution to this is literally to change the last line of url.js from exports.Url = Url; to exports.URL = Url;. For now I'm just going to make the change locally I guess.

I should note that this is specifically for parity with the native Node module. The class is called URL in that, not Url (at least at the time of writing this.)

ljharb commented 2 years ago

@Lazauya i don't think that's quite the same thing; i'm pretty confident the Url class is not a WHATWG-compliant URL replacement.

Lazauya commented 2 years ago

You are correct, now that I look more closely at it. It's strange that Parcel relies on it as such, I think I'll file a bug report over there.

MrMYHuang commented 2 years ago

I browserify url to my package url-myh by adding this: https://github.com/MrMYHuang/node-url/blob/66254d75eb169565d1290aae43337b0973a5fa87/url.js#L774

It works well with a combination of webpack 5 + node-polyfill-webpack-plugin-myh (using url-myh) + node-downloader-helper + memfs-myh. This is an example: https://github.com/MrMYHuang/taa