Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "URL is not a constructor" error in the browser #61

Merged

Conversation

mariosant
Copy link
Contributor

@mariosant mariosant commented May 30, 2018

This should fix #60.

Unfortunately, I haven't found a way to test it under browser environment. Any help would be appreciated.

@sindresorhus
Copy link
Owner

I think a conditional would be better. That way we won't bundle the whole url lib in the browser, and when we target Node.js 10, we can remove the require.

@mariosant
Copy link
Contributor Author

More like that, @sindresorhus ?

@mariosant mariosant changed the title Assign URL to a different name Fix #60 - URL is not a constructor May 30, 2018
@sindresorhus
Copy link
Owner

No, Node.js 10 also has the URL global, so the conditional should be whether the URL global already exists.

const URLParser = typeof URL === 'undefined' ? require('url').URL : URL;

@mariosant
Copy link
Contributor Author

mariosant commented May 31, 2018

Gotcha! I believe this does the trick @sindresorhus.

@sindresorhus sindresorhus changed the title Fix #60 - URL is not a constructor Fix "URL is not a constructor" error in the browser May 31, 2018
@sindresorhus sindresorhus merged commit 70b5afb into sindresorhus:master May 31, 2018
@sindresorhus
Copy link
Owner

Looks good :)

@mariosant mariosant deleted the fix/url-is-not-constructor branch May 31, 2018 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[3.0.0] URL is not a constructor
2 participants