Error Echo is not Defined

。_饼干妹妹 提交于 2019-12-11 15:13:06

问题


I'm using pusher and have been trying to configure Laravel Echo as guided in the docs. I have added the following code to bootstrap.js

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '###key###',
    cluster: 'ap2',
    encrypted: true
});

After compiling and running the code and I try to use Echo to subscribe to a channel, I get the console error that Echo is not defined.

I suspect that when Laravel Mix (5.4) is compiling the assets, it is not including bootstrap.js where Echo is defined. To confirm this, I check the contents of the compiled app.js and sure enough, the content from the bootstrap.js file are not there.

So, how do I ensure that bootstrap.js is also compiled, or how do I go about all this?


回答1:


I detected why bootstrap.js was not being compiled together with the rest of the code. I will write it here because it may be benefit someone else.

The problem was that in the process of making edits to app.js, I had removed the line require('./bootstrap'), which is the line that imports bootstrap.js (probably I thought it is meant to include Twitter Bootstrap).

Just that. It now works well. HTH!



来源:https://stackoverflow.com/questions/49144745/error-echo-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!