Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CharlesCook's avatar

Breeze, Vue, Inertia SSR, ReferenceError: Echo is not defined

I'm just trying out SSR now, and this error wont go away. Echo or window.Echo in .vue file. window.Echo return a ReferenceError: window is not defined.

ssr.js file line 2965 :

const channel = Echo.channel('AdminChannel');
returns error

but no error from line 654 :

const UserChannel = Echo.private("UserChannel");

0 likes
4 replies
CharlesCook's avatar

Well I figured it out, or have a work around. I added the channel to a function that is control by a button :

let channel = ''; //Echo.channel('AdminChannel');
function start_listening() {
   channel = Echo.channel('AdminChannel');
   channel.listen('AdminEvent', (e) => {} 

At first I tried a setTimeout, but no length of time work. It seems to require human interface, like an activate voice button.

CharlesCook's avatar
CharlesCook
OP
Best Answer
Level 1

Well there were more bugs than I thought. Double Rendering of Text when leaving channels and coming back. Fix, if others need it: Start chat .vue:

import Echo from 'laravel-echo';
import Pusher from 'pusher-js';

function open_chat() {

    window.Pusher = Pusher;
    window.Echo = new Echo({
        broadcaster: 'pusher',
        key: '55555555555',
        cluster: 'mt1',
        forceTLS: true,
        enabledTransports: ['wss', 'ws'],
    });
    channel = window.Echo.channel('AdminChannel');
    channel.listen('AdminEvent', (e) => {}

leave channel isn't enough to prevent doubles. Close chat:

    window.Echo.leaveChannel('AdminEvent');
    window.Echo.disconnect();

php controller:

broadcast(new AdminEvent($room_id, $user_id, $message))->toOthers();

Event:

use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;

class AdminEvent implements ShouldBroadcastNow
Len@ProjektGopher.com's avatar

SSR means server-side rendering. This means that when compiling your assets, there is no browser window. This is why you're seeing window is not defined. When using SSR, you're going to want to assign Echo in an onMounted() hook.

Please or to participate in this conversation.