Skip to content

Cannot read properties of undefined (reading 'addListener') or NativeAppEventEmitter is undefind #84

@Fyrnx

Description

@Fyrnx

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')

the error
Screenshot 2024-09-28 at 03-17-23

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions