繁体   English   中英

ReferenceError:nodejs中未定义窗口

[英]ReferenceError: window is not defined in nodejs

var pahoMqtt = require("paho-mqtt");
let client = new Paho.MQTT.Client("serverIp", port, "/ws", "clientId" + Math.round((new Date()).getTime() / 1000));

当我在节点服务器上运行此命令时,出现以下错误

stack: 
   [ 'ReferenceError: window is not defined',
     '    at LibraryFactory (/var/www/html/btrade/server2/node_modules/paho-mqtt/paho-mqtt.js:2411:4)',
     '    at ExportLibrary (/var/www/html/btrade/server2/node_modules/paho-mqtt/paho-mqtt.js:86:20)',
     '    at Object.<anonymous> (/var/www/html/btrade/server2/node_modules/paho-mqtt/paho-mqtt.js:97:3)',
     '    at Module._compile (module.js:652:30)',
     '    at Module._extensions..js (module.js:663:10)',
     '    at Object.require.extensions.(anonymous function) [as .js] (/var/www/html/btrade/server2/node_modules/babel-register/lib/node.js:152:7)',
     '    at Module.load (module.js:565:32)',
     '    at tryModuleLoad (module.js:505:12)',
     '    at Function.Module._load (module.js:497:3)',
     '    at Module.require (module.js:596:17)',
     '    at require (internal/module.js:11:18)',
     '    at Object.<anonymous> (/var/www/html/btrade/server2/server/controllers/trade.controller.js:25:16)',
     '    at Module._compile (module.js:652:30)',
     '    at loader (/var/www/html/btrade/server2/node_modules/babel-register/lib/node.js:144:5)',
     '    at Object.require.extensions.(anonymous function) [as .js] (/var/www/html/btrade/server2/node_modules/babel-register/lib/node.js:154:7)',

任何人都可以帮助我如何在节点js中使用Paho.MQTT。 提前谢谢。

Paho Javascript客户端当前仅在浏览器中受支持。

目前正在进行更新工作,因此它可以在NodeJS中运行,但目前尚未完成。

现在,您可以使用MQTT.js库。 该库可以在NodeJS和浏览器中使用,并支持Websockets上的本机MQTT和MQTT(当在Websockets上的MQTT上的浏览器中使用时,可以使用)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM