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.

"io is not defined"

See original GitHub issue

Hi,

I’m trying to integrate the mean stack (linnovate) with socket.io and I got this error " io is not defined". The issue is also referenced here https://github.com/linnovate/mean/issues/272.

//server.js
var server = require('http').createServer(app);
var io = require('socket.io').listen(server, {
    'log level': 2
});
io.sockets.on('connection', function(socket) {
    console.log('Client Connected');
}); //<<<<<< 'socket' is defined but never used (linting error)
...
server.listen(port); 
//public/js/services/socket.js
angular.module('mean.socket').factory('socket', ['$rootScope',  function ($rootScope) {
    var socket = io.connect();
    return {
... // like Brian Ford did
    }
}]);
// app/views/includes/foot.html which feeds into the index.html
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/js/services/socket.js"></script>
// public/js/app.js
angular.module('mean', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles', 'mean.socket']);
angular.module('mean.socket', []);

This is the error

Linting server.js ...ERROR
[L56:C44] W098: 'socket' is defined but never used.
io.sockets.on('connection', function(socket) {
Linting public/js/services/socket.js ...ERROR
[L4:C18] W117: 'io' is not defined.
  var socket = io.connect();

I don’t know what I am missing. I have no error consoled to the browser, socket.io.js is loaded properly, socket.io starts server side but nothing works. I have tried to give specific url to io.connect(), load socket.io.js from cdn but it doesn’t change. ‘io is not defined’, what does it mean, any help, any hint greatly appreciated. Trang

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:17

github_iconTop GitHub Comments

2reactions
jspeevcommented, Dec 11, 2014

You can also tell JSHint that io is a global variable. it recognizes this comment notation and won’t bother warning you that io isn’t being defined in your service (which it doesn’t need to be since it’s global) just put this before your module declaration at the top of your factory service

/* globals io */ angular.module(…

1reaction
Anachroncommented, Feb 16, 2022

You’re a bot, no?

Why do you reply to a 7 year old thread with no meaningful reply whatsoever?

Read more comments on GitHub >

github_iconTop Results From Across the Web

socket.io - ReferenceError: io is not defined - Stack Overflow
I tried it in Chrome, and it's giving me an Uncaught ReferenceError: require is not defined for the socket.io.js file. So I decide...
Read more >
Step.9 Uncaught ReferenceError: io is not defined at main.js:45
The first error shows that the /socket.io/socket.io.js did not load. As a result, io is not defined and fails. Did you run "npm...
Read more >
iOS : socket.io - ReferenceError: io is not defined - YouTube
iOS : socket.io - ReferenceError: io is not defined [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] iOS : socket.io ...
Read more >
Advanced Node and Express: ReferenceError: io is not defined
After looking at this SO discussion, I replaced "socket.io": "~2.3.0" in the package.json file with "@types/socket.io": "~2.3.0" . However ...
Read more >
NameError: name 'io' is not defined - Coding - PsychoPy
In the console I get this error “NameError: name 'io' is not defined”. What specifically went wrong when you tried that?:
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