Laravel Echo - default.a.channel is not a function

Mistre83 picture Mistre83 · Sep 14, 2016 · Viewed 11.3k times · Source

I'm trying to setup Laravel Echo with pusher, to implement real time notifications.

First, i have installed Laravel Echo and Pusher:

npm install --save laravel-echo pusher-js

After this, in bootstrap.js i have uncomment the code (as guide say):

import Echo from "laravel-echo"

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'my_key',
    encrypted: true
});
Echo.channel('orders')
    .listen('TestEvent', (e) => {
        console.log('pippo');
    });

I have run gulp and now when i visit the page, i get this error:

bootstrap.js?5e63:50 Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_laravel_echo___default.a.channel is not a function

Answer

baikho picture baikho · Sep 14, 2016

Changing Echo.channel('orders') to window.Echo.channel('orders') should fix that.