react-native: Creating an instance of URL like: `new URL('http://facebook.com')` throws an exception.
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment: OS: macOS Sierra 10.12.6 Node: 8.6.0 Yarn: 0.24.6 npm: 5.3.0 Watchman: 4.7.0 Xcode: Xcode 8.3 Build version 8E162 Android Studio: 2.3 AI-162.3934792
Packages: (wanted => installed) react: 16.0.0-alpha.12 => 16.0.0-alpha.12 react-native: ^0.48.4 => 0.48.4 Target Platform: iOS (10.3)
Steps to Reproduce
- Create a ReactNative project, which uses React Native 16
- Try to create an instance of
URL
in any .js file, like this:const url = new URL('http://facebook.com');
- Run the project
Expected Behavior
The URL to be the native URL, this one. It was working fine in React 15, but in React 16 it was replaced with something internal. We use URL to parse URLs and extract information about the hostname, port, etc. so we need this behaviour back.
Actual Behavior
An exception is thrown: Creating BlobURL objects is not supported yet.
Reproducible Demo
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 44
- Comments: 39 (6 by maintainers)
Commits related to this issue
- React sync for revisions 85d05b3...4eeee35 Summary: This sync includes the following changes: - **[4eeee358e](https://github.com/facebook/react/commit/4eeee358e )**: [SuspenseList] Store lastEffect b... — committed to facebook/react-native by gaearon 5 years ago
- deps: Add `react-native-url-polyfill`. React Native does have its own built-in polyfill for the URL Web API [1], but it's so minimal that it has some serious bugs, and a React Native maintainer has e... — committed to chrisbobbe/zulip-mobile by chrisbobbe 4 years ago
- deps: Add `react-native-url-polyfill`. React Native does have its own built-in polyfill for the URL Web API [1], but it's so minimal that it has some serious bugs, and a React Native maintainer has e... — committed to chrisbobbe/zulip-mobile by chrisbobbe 4 years ago
- deps: Add `react-native-url-polyfill`. React Native does have its own built-in polyfill for the URL Web API [1], but it's so minimal that it has some serious bugs, and a React Native maintainer has e... — committed to chrisbobbe/zulip-mobile by chrisbobbe 4 years ago
@hramos if a polyfill existing is reason enough to close this issue then I think the React Native team should deprecate the URL module and outsource it to the community as they have with others. This weird, multi-year, limbo state of the URL module is not good…
This can be worked around. Add this little piece of nastiness to your
index.js
:Closing as a workaround is provided in https://github.com/facebook/react-native/issues/16434#issuecomment-557956079
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.
requiring
the module seemed to work for me:I’m trying to parse a URL. The
URL
class is perfect for that. I don’t see anything in the docs mentioning you’ve guttedURL
for “bundle size” reasons.What’s really cool about that is that is that it works just fine in testing because
jest
is running in a completely different environment to what the app actually will, so I’ve had something inmaster
for about a week that simply breaks immediately.Could y’all fix this, please? The way I see it,
URL
, being pretty standard and built in, isn’t going to change much. Likely means the first time someone downloads an app will be the last time they downloadURL
, so bundle size be damned - that always takes ages anyway. At least let me, as a developer, opt in to the butchery.👋 You should check this out: https://github.com/charpeni/react-native-url-polyfill.
React-native seems to replace URL with this one, to support local blob urls: https://github.com/facebook/react-native/blob/master/Libraries/Blob/URL.js
not stale bot! Really annoying this issue! =\
Any updates? This is still an issue in 0.56 …
Sad, another basic feature missing.
Any updates on this??
@phillbaker what @ipeychev meant is the URL definition: https://developer.mozilla.org/en-US/docs/Web/API/URL not a custom module
+1 any update?
Same here. This would be nice to use when parsing URLs for deep link routing.
Still seeing this. RN version
"^0.58.6"
Reproduced with: Environment: OS: Windows 10 Node: 6.12.3 Yarn: Not Found npm: 3.10.10 Watchman: Not Found Xcode: N/A Android Studio: Version 3.0.0.0 AI-171.4443003
Packages: (wanted => installed) react: 16.2.0 => 16.2.0 react-native: 0.53.3 => 0.53.3