Skip to content
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 #873

Closed
zeeshanjan82 opened this issue Aug 13, 2015 · 11 comments
Closed

TypeError: io is not a function #873

zeeshanjan82 opened this issue Aug 13, 2015 · 11 comments

Comments

@zeeshanjan82
Copy link

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

@nkzawa
Copy link
Contributor

nkzawa commented Nov 27, 2015

This looks really a basic error and it's more likely something wrong with your settings. Feel free to reopen.

@nkzawa nkzawa closed this as completed Nov 27, 2015
@TheMaverickProgrammer
Copy link

having same problem. What settings?

@aaronbalthaser
Copy link

Im having the same issue. What settings?

@mrtplnkr
Copy link

having same problem. What settings?

@attack-monkey
Copy link

Same problem here using Parcel.js / Typescript as the ES6 bundler

@renatosvo
Copy link

renatosvo commented Sep 7, 2018

import * as io from 'socket.io-client';
solves the problem.

@TheMaverickProgrammer
Copy link

What if were using plain old JavaScript?

@Kacppian
Copy link

Use io.connect() instead of io().

@rishat5081
Copy link

io.connect() can't solve the problem, issue is still there

@Tzahile
Copy link

Tzahile commented Nov 20, 2019

for me the combination of @renatosvo and @Kacppian suggestions worked:
import * as io from "socket.io-client";
let ioClient = io.connect();

@dharmendrashah
Copy link

dharmendrashah commented Mar 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests