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

React Native compatibility? #24

Open
benallfree opened this issue Feb 24, 2021 · 3 comments
Open

React Native compatibility? #24

benallfree opened this issue Feb 24, 2021 · 3 comments

Comments

@benallfree
Copy link
Contributor

window.DOMParser is preventing this from working in React Native. Any ideas?

let domParser = new window.DOMParser();

@Luuka
Copy link
Owner

Luuka commented Feb 24, 2021

Hello,

I don't know how React Native works but for Node.js environment I included a DOM polyfill (https://github.com/rstacruz/jsdom-global).

if(typeof module !== 'undefined'){
    require('jsdom-global')();
    module.exports = gpxParser;
}

It's already included in GPXParser but you may need to include it in a different way to make it works with React Native.

Fell free to give me the solution if you found it, I will add it to the Readme :)

@benallfree
Copy link
Contributor Author

benallfree commented Feb 24, 2021

Thanks for the quick response :)

I figured out it's because React Native's bundler (Metro) uses the browser entry point in package.json (docs), which is a noop and doesn't import jsdom.

One solution might be to remove the browser entry and browswer.js and just use the main and index.js with some sniffer code:

if (typeof document != 'undefined') {
  // I'm on the web!
}
else if (typeof navigator != 'undefined' && navigator.product == 'ReactNative') {
  // I'm in react-native
}
else {
  // I'm in node js
}

https://stackoverflow.com/questions/39468022/how-do-i-know-if-my-code-is-running-as-react-native/39473604

@ally-garton
Copy link

Hi,

Is there a solution to this at all? I'm having the same issue and I can't find an answer anywhere.

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

No branches or pull requests

3 participants