3

I use socket-io.client library in ReactNative app. It works great on iOS but crashes android application.

Error in packager:

Directory ..node_modules\engine.io-client\lib\transports\index.j\lib\xmlhttprequest.js doesn't exist

react-native-cli: 2.0.1 react-native: 0.40.0

I trying react-native 0.39 and get same error.

olegdev
  • 41
  • 2
  • I have no specific code for this issue. Just install socket-io.client like a regular node module (npm install ..) in react project and trying import socket-io.client in js file. That's all – olegdev Jan 18 '17 at 19:52

1 Answers1

2

I was having the same issue, it is caused by how the library is imported.

var io = require("socket.io-client/dist/socket.io");

In your constructor

constructor(props) {
    super(props);
    this.socket = io('http://10.0.2.2:3000', { jsonp: false });
}

If you are using an Android emulator, use 10.0.2.2 to connect to a node server running locally on your development machine.

Community
  • 1
  • 1
gamedevranjit
  • 91
  • 1
  • 8