[英]React Native MQTT Module `url` does not exist in the Haste module map
I want to explore this project https://github.com/mqttjs/MQTT.js within the React Native environment. 我想在React Native环境中探索这个项目https://github.com/mqttjs/MQTT.js 。 So I did this:
所以我这样做了:
react-native init myproject
npm install --save mqtt
Then I pasted this sample code from the mqttjs into my App.js a bit after the "Welcome to React Native" component. 然后我将这个示例代码从mqttjs粘贴到我的App.js中,稍后是“欢迎使用React Native”组件。
var mqtt = require('mqtt')
var client = mqtt.connect('mqtt://test.mosquitto.org')
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})
But when I run react-native run-android
, I get a compilation error with a message like 但是,当我运行
react-native run-android
,我收到一个编译错误消息,如
Module
url
does not exist in the Haste module mapHaste模块映射中不存在模块
url
I tried replacing mqtt://test.mosquitto.org
with a url to my own mosquitto broker with some of these values: mqtt://192.168.0.20
, tcp://192.168.0.20
, 192.168.0.20
. 我试着更换
mqtt://test.mosquitto.org
一个网址与这些价值观我自己mosquitto经纪人: mqtt://192.168.0.20
, tcp://192.168.0.20
, 192.168.0.20
。 But all these still generated the same error. 但所有这些仍然产生了同样的错误。
What am I doing wrong? 我究竟做错了什么?
您可以通过显式安装url模块来解决此问题:
npm install url
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.