question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating an instance of URL like: `new URL('http://facebook.com')` throws an exception.

See original GitHub issue

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

  1. Create a ReactNative project, which uses React Native 16
  2. Try to create an instance of URL in any .js file, like this:
    const url = new URL('http://facebook.com');
    
  3. 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.

screen shot 2017-10-17 at 18 15 19

Reproducible Demo

https://snack.expo.io/SJUA5i7TZ

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:44
  • Comments:39 (5 by maintainers)

github_iconTop GitHub Comments

29reactions
Slapboxcommented, Sep 18, 2021

@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…

21reactions
mike-marcaccicommented, May 25, 2018

This can be worked around. Add this little piece of nastiness to your index.js:

// see https://github.com/facebook/react-native/issues/14796
import { Buffer } from "buffer";
global.Buffer = Buffer;

// see https://github.com/facebook/react-native/issues/16434
import { URL, URLSearchParams } from "whatwg-url";
global.URL = URL;
global.URLSearchParams = URLSearchParams;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there an utility to parse an URL without checked exception ...
You can construct it using either of the following ways: new URI() , which throws a checked exception; URI.create() , which throws an...
Read more >
react-native-url-polyfill - npm
A lightweight and trustworthy URL polyfill for React Native. Latest ... Creating an instance of URL like: new URL('http://facebook.com') throws an exception ......
Read more >
Handle Errors - Graph API - Meta for Developers
The Handle Errors for Graph API Requests guide describes the errors and possible reasoning for requests that receive an error.
Read more >
Source code - javadoc.io
</li> 067 * <li>Delete an object: use {@link #deleteObject(String, Parameter. ... 103 * @throws FacebookException 104 * If an error occurs while performing ......
Read more >
Facebook error: “Can't load URL: The domain of this URL isn't ...
If you don't have a Sharetribe website, these instructions won't apply, and you should contact your own service provider. When you set up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found