Laravel Echo - default.a.channel is not a function
Asked Answered
C

1

39

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
Cammack answered 14/9, 2016 at 7:4 Comment(0)
R
120

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

Rilda answered 14/9, 2016 at 19:46 Comment(3)
Very niceeeeeeeeeeee!Protist
Still helping in 2021! Thank you for this!Shanda
and don't forget npm run dev or npm run build (vite) sometimes this can cause errors like this tooMariquilla

© 2022 - 2024 — McMap. All rights reserved.