question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: io is not a function

See original GitHub issue

I am using Laravel echo like so in my bootstrap.js

import Echo from 'laravel-echo';

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'http://localhost:3000',
});

I am using Laravel’s inbuilt webpack to transpile my JS. And I am getting this on my console:

app.js:6604 Uncaught TypeError: io is not a function
    at SocketIoConnector.connect (app.js:6604)
    at SocketIoConnector.Connector (app.js:6172)
    at new SocketIoConnector (app.js:6594)
    at new Echo (app.js:6691)
    at Object../resources/assets/js/bootstrap.js (app.js:66564)
    at __webpack_require__ (app.js:679)
    at fn (app.js:89)
    at Object../resources/assets/js/app.js (app.js:66448)
    at __webpack_require__ (app.js:679)
    at fn (app.js:89)

I can’t find in the documentation on how can I import io into Echo. Any ideas?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

12reactions
AndrewMastcommented, Mar 28, 2018

(Just so the question is explicitly answered…)

io must be a function:

import Echo from 'laravel-echo';

window.io = require('socket.io-client');

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'http://localhost:3000',
});

or you must provide a client:

import Echo from 'laravel-echo';

window.Echo = new Echo({
    broadcaster: 'socket.io',
    client: require('socket.io-client'),
    host: 'http://localhost:3000',
});
1reaction
connectkushalcommented, Mar 30, 2018

@AndrewMast cool, thanks for the code snippet 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: io is not a function · Issue #1287 - GitHub
You want to: report a bug request a feature Current behaviour socket.io does not work, throws obtuse error message when trying to implement....
Read more >
TypeError: io.connect is not a function - Stack Overflow
I am having a problem when i am trying to connect to the socket server. I get an error saying TypeError: io. connect...
Read more >
Migrating from 2.x to 3.0 - Socket.IO
A v3 client is still not be able to connect to a v2 server though. ... TypeError: stream_1.pipeline is not a function at...
Read more >
Error node js socket io socket io js not found - Edureka
Getting the error: /socket.io/socket.io.js 404 (Not Found) Uncaught ReferenceError: io is not defined. My code is:
Read more >
i got this error TypeError require listen is not a function - Reddit
i got this error TypeError require listen is not a function ... var io = require('socket.io').listen(server); io.on('connection',(socket)=>{
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found