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 Horizon client issue - fetch import #477

Closed
arthurvi opened this issue May 21, 2016 · 27 comments
Closed

React native Horizon client issue - fetch import #477

arthurvi opened this issue May 21, 2016 · 27 comments

Comments

@arthurvi
Copy link

Client version: 1.0.2

When using the horizon client in React Native by calling import Horizon from '@horizon/client'; you get the following error: Unable to resolve module imports?this=>global!exports?global.fetch!isomorphic-fetch from ....

The problem is this line: https://github.com/rethinkdb/horizon/blob/next/client/src/util/fetch.js#L6. I think it is a way to shim modules with webpack. I'm not entirely sure how to fix it? React Native had its own implementation of global.fetch by default, so we should use that instead of a module. Any ideas?

simulator screen shot 21 mei 2016 20 08 57

@jonatansberg
Copy link

jonatansberg commented May 22, 2016

Just removing or commenting out that line and the line above inside node_modules/@horzon/client/lib/util/fetch.js will allow the packager to continue. Things still break when engine.io-client is initialized though.

To fix that you need to replace engine.io-client with the react-native-engine.io-client fork util this React Native packager issue is fixed.

Edit: Still doesn't work though, but now there's no obvious errors. It just fails silently. :/

@flipace
Copy link
Contributor

flipace commented May 22, 2016

Oh my. Why does this still fail for some? The error above means that the imports-loader cant be found. Could you test if it works if you replace "imports" and "exports" with "imports-loader" and "exports-loader"? Are you bundling with webpack?

@arthurvi
Copy link
Author

@mrlundis Jup, too bad.
@flipace Replacing imports and exports does not work. I'm using the default React Native packager.

@jonatansberg
Copy link

@flipace I'm also trying to run horizon inside a React Native app and I get the same error when replacing imports and exports as you suggested.

@flipace
Copy link
Contributor

flipace commented May 22, 2016

Okay thanks for the info. I thought this issie was resolved, but it seems that it's still open for react native/non-webpack packagers. Will try to find a different workaround. Thanks for trying!

@arthurvi
Copy link
Author

arthurvi commented May 22, 2016

@flipace In Relay they had an issue with RN and fetch as well. facebook/relay#26
But I did not find the solution they went for in this thread. Maybe check whether global.fetch is already defined?

global.self = global;
if (!global.fetch) {
   require('imports-loader?this=>global!exports-loader?global.fetch!isomorphic-fetch');
}

@arthurvi arthurvi reopened this May 22, 2016
@deontologician deontologician added this to the Triaging... milestone May 25, 2016
@deontologician deontologician modified the milestones: Release 1.x.x, Triaging... May 26, 2016
@rt2zz
Copy link

rt2zz commented Jun 1, 2016

@arthurvi afaik you cannot do conditional requires in RN.

What exactly does require('imports-loader?this=>global!exports-loader?global.fetch!isomorphic-fetch'); do? is that a webpack syntax?

@deontologician
Copy link
Contributor

Yeah, it's webpack syntax. Maybe there's some way we can move that stuff into the webpack config. I think you can apply certain modifiers automatically

@arthurvi
Copy link
Author

arthurvi commented Jun 1, 2016

@rt2zz Bummer, haven't tested it.
Yes it is: Webpack - shimming modules
I have never used it, but you can influence the way dependencies are imported and exported.

@deontologician
Copy link
Contributor

Ok, so we should probably special case fetch in the config to use the imports loader stuff. I'll check it out later today. I've been meaning to look closer at webpack, it's kind of a beast

@alexbezhan
Copy link

I'm also having this issue. Any possible temp workaround, guys?

@jvorcak
Copy link

jvorcak commented Jun 8, 2016

+1

@jvorcak
Copy link

jvorcak commented Jun 10, 2016

@flipace what do you mean by "open for non-webpack programmers"? I'm using Webpack and I still get this issue. What do I do wrong? I just import Horizon from '@horizon/client'; and get the error. Shall I install some loader package? Is there some workaround you can think of?

I thought installing npm install imports-loader exports-loader --save would help.

@CoreyTrombley
Copy link

Same, I can't use horizon at the moment. This makes me a sad 🐼

@mglukhovsky
Copy link
Member

@jvorcak, @CoreyTrombley, @OleksandrBezhan: unfortunately, you're pulling in the source for the client that includes unprocessed Webpack directives. You can try to import the compiled client library with:

import Horizon from '@horizon/client/dist/horizon';

We're working on improving the package to make this easier. Sorry you ran into this!

@jvorcak
Copy link

jvorcak commented Jun 14, 2016

@mglukhovsky is there any workaround you could suggest for now? I'd like to at least experiment and learn till it's ready.

@deontologician
Copy link
Contributor

@jvorcak try importing @horizon/client/dist/horizon this has no webpack directives in it

@jvorcak
Copy link

jvorcak commented Jun 14, 2016

@deontologician thanks for the help. However, this one I tried before and didn't really help. I start getting this error http://pastebin.com/A0J35b9C and the only thing I do is import Horizon from '@horizon/client/dist/horizon';

I've also tried switching to different version, modifying the code with no luck.

In React native I get Unable to resolve module http from .....node_modules/ws/lib/WebSocket.js

@deontologician
Copy link
Contributor

Ok, yeah we need to dig more into this still, sorry you're running into this

deontologician pushed a commit that referenced this issue Jun 15, 2016
…#477, #420) (#593)

* remove isomorphic-fetch and imports/exports loaders, use whatwg-fetch, replace webpack specific syntax in fetch.js and move it to webpack config

* remove deprecated loaders

* Revert "remove deprecated loaders"

This reverts commit 90bc2d0.
deontologician pushed a commit that referenced this issue Jun 16, 2016
…#477, #420) (#593)

* remove isomorphic-fetch and imports/exports loaders, use whatwg-fetch, replace webpack specific syntax in fetch.js and move it to webpack config

* remove deprecated loaders

* Revert "remove deprecated loaders"

This reverts commit 90bc2d0.
@jimthedev
Copy link

Hi @deontologician. I see a commit in the next branch. Is this something that fixes this issue so that we can get back to working with horizon and react native?

@flipace
Copy link
Contributor

flipace commented Jun 22, 2016

@jimthedev still waiting for someone to try and see if this fixes the issue for react native too, yes.

@deontologician deontologician modified the milestones: Release 1.x.x, First post-2.0 release Jun 28, 2016
@danvass
Copy link

danvass commented Jul 13, 2016

@deontologician Are there any updates yet on supporting React Native? Would like to use Horizon in conjunction with React Native but can't seem to resolve this issue.

I tried the latest client from the repo and it resolve the import error but now I am getting this issue:
undefined is not an object (Evaluating ‘window.location.search’) at auth.js:154. Ended up resolving this as well by adding a few things to line 154 but it seems to never fire onReady.

@deontologician
Copy link
Contributor

I've removed fetch in PR #619 , so it's possible that will fix at least part of the problem (one less polyfill). window.location.search is not part of this issue

@daniel1943
Copy link

daniel1943 commented Jul 14, 2016

Also having this issue(not using react native) but this boilerplate.

{ Error: Cannot find module 'imports?this=>global!exports?global.fetch!isomorphic-fetch' at Function.Module._resolveFilename (module.js:440:15) at Function.Module._load (module.js:388:25) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/home/dev/unv/node_modules/@horizon/client/src/util/fetch.js:6:1) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) code: 'MODULE_NOT_FOUND' }

@deontologician deontologician modified the milestones: Release 2.0, First post-2.0 release Jul 15, 2016
@deontologician
Copy link
Contributor

Ok, fetch has been completely removed, along with the webpack directive to make it a global.

@FrancisMurillo
Copy link

I am hooking up my react-native app with the horizon server and I am still having the same issues as @dvassilev. Tried using import "@horizon/client" and import "@horizon/client/dist/horizon" and with the same issues as with the isomorphic fetch and window.location.search.

Using version 1.1.3

@jimthedev
Copy link

@FrancisMurillo if I understand correctly, this hasn't been released yet to npm. It is in master and will be released with the 2.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests