That looks spot on :) Can you see if you can access Echo in the browser console ?
Nov 1, 2022
11
Level 4
Laravel Echo cannot be found [Vite]
I am having an issue where after migrating to vite from mix laravel echo does not seem to wrok properly.
I am getting the error: "Laravel Echo cannot be found" in the console. more so a warning actually. The connection does not come trough properly but I can see on laravel-websockets dashboard that there was an attempt.
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
@vite(['resources/css/app.css'])
@vite(['resources/js/app.js'])
@livewireScripts
@livewireStyles
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/iziToast.min.js" defer></script>
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
</head>
The JS is loaded BEFORE the livewireScripts. (Ive tried after aswell no difference..)
My bootstrap.js
import _ from 'lodash';
window._ = _;
import axios from 'axios';
window.axios = axios;
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
import Echo from 'laravel-echo';
import Pusher from 'pusher-js';
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'pusher',
key: import.meta.env.VITE_PUSHER_APP_KEY,
cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
wsHost: window.location.hostname,
wsPort: 6001,
wssPort: import.meta.env.VITE_PUSHER_APP_PORT,
disableStats: true,
enabledTransports: ['ws', 'wss'],
forceTLS: (import.meta.env.VITE_PUSHER_APP_SSL === 'true'),
encrypted: false,
});
Level 102
@ItsClassified It might be due to vite doing splitting so it loads it separately, which takes a split second (but might be too slow)
1 like
Please or to participate in this conversation.