happyDemon / vue-echo

Vue integration for the Laravel Echo library.
228 stars 24 forks source link

Uncaught ReferenceError: io is not defined #5

Closed bigperson closed 7 years ago

bigperson commented 7 years ago
import VueEcho from 'vue-echo';
Vue.use(VueEcho, {
    broadcaster: 'socket.io',
    host: 'http://site.local:6001'
});

Error: Uncaught ReferenceError: io is not defined

terion-name commented 7 years ago

+1

happyDemon commented 7 years ago

@bigperson @terion-name Have you guys included the socket io library somewhere? the same setup is required as laravel echo.

If you did it might be better to register VueEcho with a configured laravel echo instance

terion-name commented 7 years ago

@happyDemon yeh, I've already figured it out, just forgot to comment.

<script src="//{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>

One big problem with this, that if socket-server is down by some reason, this breaks the entire app. I think that this needs to be inserted dynamically with error handling, a theme to think about

happyDemon commented 7 years ago

@terion-name This is something you might better report at laravel-echo, since this is just a wrapper around that lib.

The general assumption from laravel-echo is that the socket io library gets imported, so it will always be available.

terion-name commented 7 years ago

@happyDemon this snippet:

<script src="//{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>

is from echo docs. if I just import IO via webpack and attach it to window — everything should work?

happyDemon commented 7 years ago

@terion-name I didn't know that they put that in the echo docs (I've only been using the pusher driver) :/

surely it's best to have all the code on the same server in case of hiccups on the socket server's side.

The socket IO client has its own package:

npm install socket.io-client --save
const io = window.io = require('socket.io-client');

// Or ES6
import * as io from 'socket.io-client';
window.io = io;
learnmove commented 7 years ago

right ,it must add const io = window.io = require('socket.io-client'); cdn way not work

codewithbhanu commented 4 years ago

Screenshot (70)

I get an Error like this main.js:1 Uncaught ReferenceError: io is not defined at main.js:1 anynone please help me.....

happyDemon commented 4 years ago

@hacker248 you have to include the library, seems like the browser can't find a reference to it.