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
import syntax throws when importing socket.io if debugger is not attached #4393
Comments
Hey adamterlson, thanks for reporting this issue! React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
|
Socket.io likely needs to write a React Native version of their library. It looks like you're trying to run a browser version of their code. |
@adamterlson I can confirm that i've used socket.io with react native and had no issues. The only caveat that I ran into earlier was that Here is an article by @browniefed that might help. In the past i've worked with https://www.npmjs.com/package/react-native-swift-socketio and it worked fine as well. Hope this helps! |
@ChristopherDo Well Socket IO works fine, but that's not really the issue. The question is why there's inconsistent behavior from RN depending on Thanks for the help! |
@adamterlson As far as I understand, all imports are hoisted to the top, while requires are not. Hence, the reason it's not working with I guess it only happens in debugger because there might be a delay somewhere while communicating via the bridge, and there is not enough delay when running on phone to cause this. I might be wrong though. Feel free to close the issue if this answers your question. |
@satya164 Good enough for me, thanks for the explanation! |
@satya164 @christopherdro Have you also experienced an issue with Socket IO not working unless the chrome debugger is attached? |
@adamterlson Nope. Working fine here. I needed to change 2 things, set the user agent, and disable jsonp. |
What version of RN did you use? Do you have a project up somewhere I can clone perhaps? |
@adamterlson I am actually using engine.io atm. But I had tested with socket.io previously. RN version shouldn't matter, because the WebSocket module hasn't changed since then. Also it's weird that it would only work with Chrome debugger. In both cases it uses the Androide module. BTW what's the error you're getting? |
So I did a fresh init and plugged socket IO in and now I have two projects running. My first project is where SocketIO only works when the Chrome Debugger is attached, and now this new one, it doesn't seem to connect in general and if the chrome debugger is attached it throws the exception also referenced here: http://browniefed.com/blog/2015/05/16/react-native-and-socket-dot-io/ I'm just all tangled up at this point. :) You can see my socketio code here as well as the entire project: Without the chrome debugger attached I don't actually see any errors, it just doesn't connect. Hard to tell more without a debugger. :) |
@adamterlson It didn't work for me without disabling JSONP. Have you tried that?
|
I'll have a proper look later tonight. |
Yup, I have tried the jsonp thing. Sorry it's excluded from the pushed version. I've updated the repo. |
@satya164 Any insights by chance? |
Sorry, didn't get a chance to have a look. Will do ASAP. |
@satya164 I'm still interested by the way, if you might find the time! :) |
@adamterlson I got the same error with socket.io. |
Seems like a good explanation. No, no fix. It seems like an open issue to me. I'll reopen and hopefully someone has some guidance! |
This isn't really an issue with react native but more of an issue with socket.io |
The issue is with the inconsistent behavior based on debugger attachment. Can you be more specific as to how the user agent is related? |
Has the error message changed from the one you originally reported complaining about |
@browniefed Thank you for the details. In some sense the actual issue is in fact not simply the error you've described and the screenshot I posted. It's more the inconsistency of behavior. As described in the thread and also experienced by @chezhe, if the debugger is attached things work fine.
If this were the case, would it not be that socket io would not work at all, ever, rather than based on whether the debugger us attached or not? I found a comment you made on this blog post a while back which states that socket io will not work with the debugger open. This thread/issue describes behavior where it only works with it open. Do you know what has changed? |
Lots of moving parts in RN, not sure exactly what is causing such things to happen. What I can say, is if you are getting the I'm not saying RN is perfect with websockets and debugging but it seems to be external library issues failing and not necessarily react native. Going forward, what errors are thrown when running on the device? I haven't seen those posted yet. |
I haven't done device testing on my end yet. @chezhe Can you post a screenshot? Though it was stated he got the "Same error" in both so I assume the whole user agent match thing. @browniefed Thank you again. I appreciate the discussion! |
Have you tried by adding |
@deyoppe now,yes. |
@deyoppe |
Also does not work with 0.25.1. |
@Mokto Try this:
|
That worked for me. Thanks a bunch, @chezhe! |
Thanks that works perfectly ! |
@chezhe thanks so much, it works like a charm ! I've been looking for solution and no hope until i saw this xD |
@satya164 I think u can close this issue |
@facebook-github-bot answered |
Closing this issue as @browniefed says the question asked has been answered. Please help us by asking questions on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only. |
I am still having this issue. Using
Using code:
Using However, if I do NOT enable "Rebug JS Remotely" I get: I have to enable remote debugging to get the error to go away. Furthermore, when building the production APK for the project, the app crashes immediately (due to the same error). Am I missing something? EDIT: I've used the technique here: http://browniefed.com/blog/react-native-and-socket-dot-io/ to fix the issue. |
|
@chezhe HUGE thanks! Been looking for this in the past hours. |
I have this issue too. My code:
And only connects if I'm in debugging mode. The console log, when I'm in debugging mode, outputs PS: Someone knows if there is an alternative of socket.io for react native ? |
Hey @lucasmaciel I'm experiencing the same problem. Did you find any fix for this? |
The code that works:
you have to write "ws://" instead of "http://". And add "transports: ['websocket']". It should works. |
Still can't make it to work 😭 I'm using 1.7.3 too in socket.io both client and server. |
@joaqtor you can check my code |
I don't know how to even begin with this one, but I'm including Socket.IO into a project spawned from react-native init. The import of the SocketIO library bombs, but only when the debugger is not attached. I can use the require syntax instead and then that works no matter what.
Always works:
let io = require('socket.io-client/socket.io');
Fails with Chrome Debugging disabled but works otherwise:
import io from 'socket.io-client/socket.io';
Here's the error for whatever good it is: "undefined is not an object (evaluating navigator.userAgent.match)"
The text was updated successfully, but these errors were encountered: