fabaff / mqtt-panel

A web interface for MQTT
MIT License
418 stars 115 forks source link

Cannot find module 'socket.io' #4

Closed tringler closed 6 years ago

tringler commented 7 years ago

Hello,

I'm receiving the error Cannot find module socket.io when I try to start the mqtt panel even I installed socket.io via npm -g install socket.io

Any idea how to get rid of this error? Here you are the full error message:

module.js:472
    throw err;
    ^

Error: Cannot find module 'socket.io'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/etc/mqtt-panel/server.js:8:14)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)

Thanks in Advance, Thomas

fabaff commented 7 years ago

Can you try to change

    <script type="text/javascript" src="http://localhost:3000/socket.io/socket.io.js"></script>

to something like

    <script type="text/javascript" src="js/socket.io.min.js"></script>
tringler commented 7 years ago

Changed to <script type="text/javascript" src="js/socket.io.min.js"></script> in index.html, but running into the same behaviour. How can I test if the module socket.io is accessible by your script?

tringler commented 7 years ago

It has been solved by npm install socket.io --save

tringler commented 7 years ago

It stops now with:

var mqttclient = mqtt.createClient(mqttport, mqttbroker);
                      ^

TypeError: mqtt.createClient is not a function
    at Object.<anonymous> (/etc/mqtt-panel/server.js:15:23)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:423:7)
    at startup (bootstrap_node.js:147:9)
    at bootstrap_node.js:538:3
tringler commented 7 years ago

I changed var mqttclient = mqtt.createClient(mqttport, mqttbroker); to var mqttclient = mqtt.connect(mqttport, mqttbroker);

Take a look at: https://github.com/mqttjs/MQTT.js/issues/247

Now it stops with:

TypeError: Parameter "url" must be a string, not number
    at Url.parse (url.js:81:11)
    at Object.urlParse [as parse] (url.js:75:5)
    at Object.connect (/etc/mqtt-panel/node_modules/mqtt/lib/connect/index.js:52:22)
    at Object.<anonymous> (/etc/mqtt-panel/server.js:15:23)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
tringler commented 7 years ago

Changed var io = socket.listen(3000); to var io = socket.listen('http://localhost:3000');

Now it stops with:

/etc/mqtt-panel/node_modules/engine.io/lib/server.js:424
  var listeners = server.listeners('request').slice(0);
                         ^

TypeError: server.listeners is not a function
    at Server.attach (/etc/mqtt-panel/node_modules/engine.io/lib/server.js:424:26)
    at Function.attach (/etc/mqtt-panel/node_modules/engine.io/lib/engine.io.js:124:10)
    at Server.listen.Server.attach (/etc/mqtt-panel/node_modules/socket.io/lib/index.js:240:21)
    at new Server (/etc/mqtt-panel/node_modules/socket.io/lib/index.js:52:17)
    at Function.Server [as listen] (/etc/mqtt-panel/node_modules/socket.io/lib/index.js:40:41)
    at Object.<anonymous> (/etc/mqtt-panel/server.js:14:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
otrab commented 7 years ago

Hi @tringler I think you use bad the mqtt method

check this https://github.com/mqttjs/MQTT.js/blob/master/examples/client/simple-both.js

whit this I can run ./runner.sh

falkTX commented 6 years ago

Why is this closed? Current code as of today does not run, I have the same errors @tringler has.

falkTX commented 6 years ago

The current change makes it work for me:

diff --git a/server.js b/server.js
index 4af2095..96838e7 100644
--- a/server.js
+++ b/server.js
@@ -9,10 +9,10 @@ var socket = require('socket.io');
 //var firmata = require('firmata');

 var mqttbroker = 'localhost';
-var mqttport = 1883;
+var mqttport = '1883';

 var io = socket.listen(3000);
-var mqttclient = mqtt.createClient(mqttport, mqttbroker);
+var mqttclient = mqtt.connect('tcp://' + mqttbroker + ':' + mqttport);

 // Subscribe to topic
 io.sockets.on('connection', function (socket) {