Electron-vue: Use socket.io-client not work

Created on 7 Dec 2017  路  6Comments  路  Source: SimulatedGREG/electron-vue

Found an issue or bug with electron-vue? Tell me all about it!

I want to use socket.io-client.
But i found not work.
I think webpack main and renderer config have error

How can I reproduce this problem?

npm install --save socket.io-client

in App.vue

import io from 'socket.io-client'

const socket = io('http://localhost/admin');

If work can connect to websocket in http://localhost/admin

Tell me about your development environment.
  • Node version: v7.2.0
  • NPM version: v5.5.1
  • vue-cli version: (if necessary)
  • Operating System: MAC

Most helpful comment

Oh, i just use "const io = require('socket.io-client/dist/socket.io')"

All 6 comments

I'm actually having trouble connecting to socket.io servers as well, specifically when running my electron app in development (after running npm run dev). It times out most of the time and the only possible way to make it work is to run it again and keep trying until it randomly works.

In production it works fine.

I've got noParse: /\bws\b/ though removing it doesn't seem to make a difference.

Node version: v9.3.0
NPM version: v5.6.0
Operating System: Windows 10

OK, this is extremely strange.

const io = require('socket.io-client/dist/socket.io')
// const io = require('socket.io-client/')

I normally use the second line, uncommented. It pretty much never works in development. However, if I use the above code when I do npm run dev, then I comment the top and uncomment the bottom, it hot-reloads and works for the rest of the dev session.

@zxc23 Yes, me too.
I think is webpack config not correct.

@imRainChen
Did you find a solution?

Oh, i just use "const io = require('socket.io-client/dist/socket.io')"

That gives me an XHR poll error when I try to connect.

Was this page helpful?
0 / 5 - 0 ratings