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

Stop using XMLHttpRequest? Use an alternative? #157

Closed
bjonnh opened this issue Dec 22, 2016 · 3 comments
Closed

Stop using XMLHttpRequest? Use an alternative? #157

bjonnh opened this issue Dec 22, 2016 · 3 comments

Comments

@bjonnh
Copy link

bjonnh commented Dec 22, 2016

I tried to use rdflib.js with react, but it fails due to XMLHttpRequest requiring child_process.

Is there a plan to remove that dependency, or should I just fork it?

@dmitrizagidulin
Copy link
Contributor

@bjonnh Thanks for reaching out.
The dependency on the XMLHttpRequest lib is not the problem. What's at issue here is that rdflib is written to be isomorphic js - that is, should run the same in the browser and server side on Node.js. This means that when used in Node.js, we have to shim the various globals that are available in the browser, such as the XMLHttpRequest global. (We use the xmlhttprequest npm library to do that.)

The benefit of being isomorphic comes with a little bit of complexity -- when you're packaging up rdflib for use in the browser, you have to remember to exclude the xmlhttprequest library (since the browser already has it).

That means, if you're using Browserify, you have to add --exclude "xmlhttprequest" to your invocation.

And if you're using Webpack (which is what I assume you're using with react), you have to add XMLHttpRequest to your externals: section in webpack config:

module.exports = {
  // ... other stuff
  externals: {
    'xmlhttprequest': 'XMLHttpRequest'
  }
}

(This tells Webpack to /not/ webpack the xmlhttprequest lib, and to substitute all instances of require('xmlhttprequest') with just the global XMLHttpRequest.)

I'm going to close this issue; please feel free to reopen if you have further questions.

@dmitrizagidulin
Copy link
Contributor

I should clarify - it's specifically the xmlhttprequest npm library that is giving you the child_process error, when Webpack tries to package it up.

@bjonnh
Copy link
Author

bjonnh commented Dec 22, 2016

Thanks for reaching out so quickly, I'll try to find a way to exclude that in my react app.

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

2 participants