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

Fix compatibility with React Native #1047

Closed
jpoutrin opened this issue May 8, 2017 · 12 comments
Closed

Fix compatibility with React Native #1047

jpoutrin opened this issue May 8, 2017 · 12 comments
Assignees

Comments

@jpoutrin
Copy link

jpoutrin commented May 8, 2017

The library does not work with react native for some reason.
when I disable swagger-js or move back to version 2 my app works again...

@ponelat
Copy link
Member

ponelat commented May 12, 2017

So the issue was Failed to print error: regeneratorRuntime.async is not a function when loading this lib into a react-native app.

I think its because we're missing the regenerator runtime... all apps up to date have included babel-polyfill and so this was mostly hidden from us. (@webron in theory this should affect any browser that didn't include its own babel-polyfill )

@jpoutrin a possible workaround is to just include babel-polyfill

But we'd need to find a fuller solution to swagger-js, as we shouldn't be mutating globals in a lib. Its just bad :)

@jpoutrin
Copy link
Author

@ponelat it might be one of the issue indeed. but didn't make it work at the end.

I moved back to v2 and also discover that the http connector had to be re-implemented as the XMLHttpRequest seem to behave in a different way.
everything was working except POST messages...
v2 is easier as plain javascript which makes it easier to debug ;)

see the gist

@adamski
Copy link

adamski commented Jun 6, 2017

I just hit this issue trying to upgrade a react-native module to v3, manifesting as a "self is not defined" error which seems to come from the fetch library.

@piranna
Copy link

piranna commented Aug 1, 2017

Any update on this? What's the current solution, or what we should be doing?

@shockey
Copy link
Contributor

shockey commented Aug 16, 2017

@piranna, some information on how swagger-client is breaking for you would be helpful.

We've removed babel-polyfill, so that shouldn't be an issue. Are you having the same fetch problem as @adamski?

@piranna
Copy link

piranna commented Aug 17, 2017

I haven't used the library yet, but was heavily interested on. I was just asking to know if it would work or should I use fetch instead.

@noproblama
Copy link

noproblama commented Aug 23, 2017

Currently faced the same trouble.
Eventually client object has empty apis parameter.

After debugging this error was found (in isomorphic-fetch lib):
image
(as @adamski noticed)

So now I am stuck at this point.
I would be happy to understand the workaround of @jpoutrin, but I don't exactly understand how it works.

I use "swagger-client": "^3.0.20".

So, I now don't know what to do. Using fetch with swagger server interface doesn't look so sweet :'(

P.S. I am wondered but I cannot find any information about using RN and Swagger client. So, either everything works great everywhere, either no one use it. No glue.

UPD.
Okay, I realized how it works. Thank you very much, @adamski.
I switched to "swagger-client": "^2.1.32".
Then using reactNativeHttpClient by @adamski (from here) my Swagger calls look like:

return new SwaggerClient({
    url: swaggerUrl,
    usePromise: true,
    client: reactNativeHttpClient,
  }).then(client => {
    return client.apis.account
      .doesEmailExist({ email })
      .then(res => {
        return res.obj.success
      })
  })

So thank you, @adamski!

Anyway, it doesn't work with 3.x :(

@shockey
Copy link
Contributor

shockey commented Aug 24, 2017

Thanks for the insights, everyone.

It looks like this is a known issue with isomorphic-fetch:

Unfortunately, it appears that the library is no longer maintained, so this is unlikely to change from their end.

In the second issue I linked, I noticed someone pointing to the fetch-everywhere as an API-compatible replacement for isomorphic-fetch. The best fix for this may be to move Swagger-Client over to fetch-everywhere internally.

@shockey
Copy link
Contributor

shockey commented Nov 2, 2017

We've just switched from isomorphic-fetch to cross-fetch, which claims to be React Native compatible 😄

@shockey
Copy link
Contributor

shockey commented Nov 4, 2017

Fix released in swagger-client@3.3.2.

Closing! Thanks everyone.

@shockey shockey closed this as completed Nov 4, 2017
@jtn-d
Copy link

jtn-d commented Nov 21, 2017

I have version 3.3.4 and facing this.

Swagger('http://petstore.swagger.io/v2/swagger.json')
  .then(client => {
    console.log(client.errors)
  })

[ { [TypeError: undefined is not a function (evaluating '$.default.apply(e, [t])')]

Am I missing something?

@shockey
Copy link
Contributor

shockey commented Nov 27, 2017

@jtn-d, that's an odd error. Is it still a problem? Can you give some more context?

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

8 participants