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

CitizenZed's avatar

spark2 + echo ReferenceError: Echo is not defined

ReferenceError: Echo is not defined

I spent some time exploring spark2.0 + laravel-echo, and here are some of the things I've worked out.. so far. By no means am I an expert on these things, and I'm probably missing something obvious.

If you instantiate Echo from resources/assets/js/bootstrap.js per the docs, it isn't available to your vue components. If you move this to the start of resources/assets/js/app.js, it is available.

In resources/assets/js/bootstrap.js you must change the object name Laravel to Spark in the Vue.http.interceptors.push {closure?} for the csrfToken.

0 likes
4 replies
kerranm's avatar

Hey CitizenZed, I can definitely vouch for the Echo bootstrap issue. I spent a good amount of time troubleshooting that one today. I didn't have to touch the CSRFToken though.

ShaneDRosenthal's avatar

I am in a similar situation - following along with Taylors Echo tutorial everything is working up to introducing Ech into the app.

I have tried moving the import around and it doesn't seem to make a difference where I put it, I continue to get "echo is not defined".

Yes, I ran the npm installer, still no luck...

Any help would be greatly appreciated.

nisbeti's avatar

Laravel out of the box imports the bootstrap.js file from app.js ( see https://github.com/laravel/laravel/blob/master/resources/assets/js/app.js )

Whereas, Spark imports spark-bootstrap.js instead, which does more-or-less the same thing.

So, instead of putting the import Echo from "laravel-echo" at the top of the app.js file, you can just include the bootstrap/echo.js file from the demo, but it must be required before require('./components/bootstrap');

Hence, app.js looks like:

require('spark-bootstrap');

require('./bootstrap/echo');

require('./components/bootstrap');

var app = new Vue({
    mixins: [require('spark')]
});
4 likes

Please or to participate in this conversation.