When trying to connect using
this._socket = io('http://localhost:5000');
I get the error TypeError: io is not a function. I can see the socket.io/socket.io.js file in the network tab and is getting loaded. I have installed socket.io using npm socket.io and am using socket.io-client version 1.3.6
This looks really a basic error and it's more likely something wrong with your settings. Feel free to reopen.
having same problem. What settings?
Im having the same issue. What settings?
having same problem. What settings?
Same problem here using Parcel.js / Typescript as the ES6 bundler
import * as io from 'socket.io-client';
solves the problem.
What if were using plain old JavaScript?
Use io.connect()
instead of io()
.
io.connect() can't solve the problem, issue is still there
for me the combination of @renatosvo and @Kacppian suggestions worked:
import * as io from "socket.io-client";
let ioClient = io.connect();
sameProblem
when i'm exporting it gives me an error the my code is
const express = require('express');
const router = express.Router();
var app = express();
const io = require('socket.io');
const fs = require('fs');
const { ensureAuthenticated } = require('../db/auth.js');
//exporting dashboard
module.exports = {
dash: router.get('/', (req,res)=>{
var chat = io.on('connection', (socket)=>{
console.log('chat is connected');
})
res.render('dashboard', {chat:chat});
})
}
and the error i'm getting is
io.on is not a function
TypeError: io.on is not a function
at E:\expressBasedLOginSignUP\routes\dashboard.js:13:19
at Layer.handle [as handle_request] (E:\expressBasedLOginSignUP\node_modules\express\lib\router\layer.js:95:5)
at next (E:\expressBasedLOginSignUP\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (E:\expressBasedLOginSignUP\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (E:\expressBasedLOginSignUP\node_modules\express\lib\router\layer.js:95:5)
at E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:281:22
at Function.process_params (E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:335:12)
at next (E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:275:10)
at Function.handle (E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:174:3)
at router (E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:47:12)
at Layer.handle [as handle_request] (E:\expressBasedLOginSignUP\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:317:13)
at E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:284:7
at Function.process_params (E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:335:12)
at next (E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:275:10)
at E:\expressBasedLOginSignUP\node_modules\express\lib\router\index.js:635:15
Most helpful comment
Use
io.connect()
instead ofio()
.