cljs-ajax icon indicating copy to clipboard operation
cljs-ajax copied to clipboard

Compatibility with react-native using nodejs target

Open olivergeorge opened this issue 6 years ago • 3 comments

The new release of re-natal (version 0.9) defaults to using :target :nodejs which seems incompatible with this code:

(def xmlhttprequest
  (if (= cljs.core/*target* "nodejs")
    (let [xmlhttprequest (.-XMLHttpRequest (js/require "xmlhttprequest"))]
      (goog.object/set js/global "XMLHttpRequest" xmlhttprequest)
      xmlhttprequest)
    (.-XMLHttpRequest js/window)))

The first error (bundling failed: Error: Unable to resolve module xmlhttprequest) is resolved by including "react-native": {"xmlhttprequest": false} in packages.json as per the FAQ.

The second error is

Error: Uncaught ReferenceError: global is not defined

Refs: https://github.com/drapanjanas/re-natal/releases/tag/v0.9.0

olivergeorge avatar Jul 13 '18 02:07 olivergeorge

I think the fundamental problem is that I don't have a travis test for a scenario like this. As a consequence, this "detect what you're running under" code is constantly breaking. If you could come up with a PR for a test, I'm pretty sure that we could reduce problems like this.

More generally, I don't understand what's happening here. In a browser, the "global" object is "js/window" and in node it's "js/global". So why this isn't working in React Native is beyond me. (I don't massively like the code we've got, but going back to what I was saying before, it's hard to fix in the absence of regression tests)

JulianBirch avatar Jul 22 '18 09:07 JulianBirch

Maybe related to #155

dijonkitchen avatar Jan 17 '19 17:01 dijonkitchen

Implementing fetch would probably be desirable and would probably fix this problem cold, agreed.

On Thu, 17 Jan 2019 at 17:34, Jonathan Chen [email protected] wrote:

Maybe related to #155 https://github.com/JulianBirch/cljs-ajax/issues/155

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JulianBirch/cljs-ajax/issues/214#issuecomment-455260258, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFIk0qbW9glbM8jrwU-BZ_e2Ak2MsyZks5vELQ_gaJpZM4VOMqK .

JulianBirch avatar Jan 18 '19 11:01 JulianBirch