Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

mqtt: net.createConnection is not a function

$
0
0

I am following this guide: https://www.npmjs.com/package/mqtt#install and to try to get an mqtt connection, but I am getting a render error saying_$$_REQUIRE_(dependencyMap[1], "net").createConnection(port, host)','_$$_REQUIRE(_dependencyMap[1], "net").createConnection' is undefined)I attached a picture of the actual error

Here is my app.tsx file (the only code that I actually wrote):

import React, { useState, useEffect } from 'react';import { StyleSheet, Text, View, TouchableOpacity, Dimensions } from 'react-native';import { connect } from 'mqtt';import { Buffer } from "buffer"export default function App() {  console.log("START")var client  = connect('mqtt://localhost:1883')client.on('connect', function () {  console.log("Connected")  client.subscribe('presence', function (err : any) {    if (!err) {      client.publish('presence', 'Hello mqtt')    }  })})client.on('message', function (topic : any, message : any) {  // message is Buffer  console.log(message.toString())  client.end()})  return (<View style = {{flex : 1}}><View style = {{flex : 1}}></View><View style = {{justifyContent:'center', alignItems:'center',alignSelf:'center', position:'absolute'}}><View           style={{backgroundColor:'rgba(255,0,0,'+ 1 +')',                 height:Dimensions.get('window').height + 100,                 width:Dimensions.get('window').width}}></View></View></View>  );}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>