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

browser-request is not compatible with react-native #875

Open
poernahi opened this issue Apr 1, 2019 · 2 comments
Open

browser-request is not compatible with react-native #875

poernahi opened this issue Apr 1, 2019 · 2 comments
Labels
Help Wanted Extra attention is needed T-Defect

Comments

@poernahi
Copy link

poernahi commented Apr 1, 2019

Production build in react-native fails because the browser-request library tries to call document.createElement to check for cross-domain request (for CORS).

In React Native, document is not defined and CORS is not relevant.

The browser-request library has not been updated since 2014, so upstream fix seems very unlikely.

I propose dependency update to https://www.npmjs.com/package/xmlhttp-request which is a fork of browser-request that fixed this problem.

@jryans
Copy link
Collaborator

jryans commented Apr 2, 2019

Thanks for raising this issue! element-hq/element-web#7634 is related and raises some complexity to consider when moving to a different request library.

If xmlhttp-request solves those issues, then it seems like a reasonable candidate.

You may be able to workaround the problem for your own application by passing a different request function into the JS SDK:

matrix-js-sdk/src/matrix.js

Lines 122 to 130 in 5c8890c

/**
* The function used to perform HTTP requests. Only use this if you want to
* use a different HTTP library, e.g. Angular's <code>$http</code>. This should
* be set prior to calling {@link createClient}.
* @param {requestFunction} r The request function to use.
*/
module.exports.request = function(r) {
request = r;
};

@jryans jryans added T-Defect Help Wanted Extra attention is needed labels Apr 2, 2019
@bradjones1
Copy link

Exploring related questions - request is in maintenance mode and xmlhttp-request hasn't been touched in many years. I think this could perhaps be closed in favor of #801 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted Extra attention is needed T-Defect
Projects
None yet
Development

No branches or pull requests

3 participants