-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: io is not a function #1287
Comments
If you downloaded this as a file, you need to add const io = require('./socket.io.slim'); |
Tried that, same behavior. |
Try using this <script src="/socket.io.slim.js"></script>
<script>
var socket = io('http://localhost:9990');
</script> OR require('./socket.io.slim');
var socket = io('http://localhost:9990'); |
I am not launching this script via HTML. I've tried that exact block of code listed and got the exact same error message I gave to start with. |
If you're using $ npm i socket.io-client and then const io = require("socket.io-client"); |
I am not using NPM. I am using the Chrome V8 engine - straight. |
Is this for sure a client, not a server script? I've tried to reproduce your code, I've downloaded > const io = require("./socket.io.slim");
> io("http://localhost:8888");
ReferenceError: document is not defined |
It's a client, as in it is connecting to a socket as a client. |
I'm running into this same issue. Were you able to find a solution @SwitchedToGitlab? |
For future readers, please see the documentation here: https://socket.io/docs/v3/client-initialization/ |
Has anybody found the solution? |
This causes an error const io = require("socket.io-client"); Solve it by using it like this: const { io } = require("socket.io-client"); or const io = require("socket.io-client").io; |
same here by using npm -> TypeError: io is not a function |
You want to:
Current behaviour
socket.io does not work, throws obtuse error message when trying to implement. Issue is most likely in documentation, code quality (code comments are helpful here, these are useless), poor answers in issue tracker.
Basically a duplicate of #873, but that was never really answered to we get to do this all over again.
Steps to reproduce (if the current behaviour is a bug)
My code stub (I've tried all kinds of permutations of this):
const io = require('socket.io.slim.js');
var socket = io('http://localhost:9990'); // TIP: io() with no args does auto-discovery
socket.on('connect', function () {
socket.emit('ferret', 'tobi', 'woot', function (data) { console.log(data); // data will be 'tobi says woot' });
});
// error message:
2019-04-09 13:08:46.166650 [ERR] undefined:6 Exception: TypeError: io is not a function (near: "var socket = io('http://localhost:9990'); // TIP: io() with no args does auto-discovery")
Expected behaviour
It to work as shown in the example.
Setup
Other information (e.g. stacktraces, related issues, suggestions how to fix)
See issue #873 for a whole bunch of other people all asking the same question.
The text was updated successfully, but these errors were encountered: