Open
Description
I'm trying to run nodejs-mobile-react-native in react-native: 0.74.5 and react-native-cli: 2.0.1
but the app won't run because of this error
Cannot read properties of undefined (reading 'addListener')
this is my code
import { Text, View } from "react-native";
import nodejs from "nodejs-mobile-react-native"
import { useEffect } from "react";
export default function Page() {
useEffect(_ => {
nodejs.start("main.js");
nodejs.channel.addListener("message",
(msg) => alert("From node: " + msg),
this
);
}, [])
return (
<View>
<Text>Hello World</Text>
</View>
);
}
and this is the package code with the error ( factory: node_modules/nodejs-mobile-react-native/index.js )
/*
* Dispatcher for all channels. This event is called by the plug-in
* native code to deliver events from Node.
* The channelName field is the channel name.
* The message field is the data.
*/
NativeAppEventEmitter.addListener("nodejs-mobile-react-native-message",
(e) => {
if (channels[e.channelName]) {
channels[e.channelName].processData(e.message);
} else {
throw new Error('Error: Channel not found:', e.channelName);
}
}
);
Metadata
Metadata
Assignees
Labels
No labels