简体   繁体   English

React Native MQTT模块`url`在Haste模块映射中不存在

[英]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 map Haste模块映射中不存在模块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.20tcp://192.168.0.20192.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.

相关问题 React native:Haste模块映射中不存在模块`DrawerLayoutAndroid` - React native: Module `DrawerLayoutAndroid` does not exist in the Haste module map React Native 问题:Haste 模块映射中不存在模块 - React Native issue: Module does not exist in the Haste module map 急速模块 map 中不存在模块“react-native-screens” - Module `react-native-screens` does not exist in the Haste module map Haste模块映射中不存在模块'react' - Module 'react' does not exist in the Haste module map 原生基础错误“Haste 模块映射中不存在模块`color`” - Error with native base “Module `color` does not exist in the Haste module map” Haste 模块映射中不存在模块 `@react-navigation/core` - Module `@react-navigation/core` does not exist in the Haste module map 模块`scheduler / tracing`在Haste模块映射中不存在react-native中的错误 - Module `scheduler/tracing` does not exist in the Haste module map Error in react-native React Native 包错误:Haste 模块映射中不存在模块`scheduler` - React Native bundle error : Module `scheduler` does not exist in the Haste module map Haste 模块 map 中不存在模块“react-navigation-tabs” - Module `react-navigation-tabs` does not exist in the Haste module map Haste 模块映射中不存在模块 `fs` - Module `fs` does not exist in the Haste module map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM