olegdev
olegdev

Reputation: 41

socket-io.clent does not work under React Native Android app

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.

Upvotes: 3

Views: 1422

Answers (1)

gamedevranjit
gamedevranjit

Reputation: 91

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.

Upvotes: 2

Related Questions