Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Fyrnx opened this issue Sep 28, 2024 · 1 comment

Comments

@Fyrnx
Copy link

Fyrnx commented Sep 28, 2024

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);
    }
  }
);
@Fyrnx
Copy link
Author

Fyrnx commented Sep 30, 2024

info Fetching system and libraries information...
System:
OS: Windows 11 10.0.22631
CPU: "(12) x64 AMD Ryzen 5 3600 6-Core Processor "
Memory: 5.81 GB / 15.95 GB
Binaries:
Node:
version: 20.12.2
path: C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm:
version: 10.5.0
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
IDEs:
Android Studio: Not Found
Visual Studio: Not Found
Languages:
Java: 21.0.4
Ruby: Not Found
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.74.5
wanted: 0.74.5
react-native-windows: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: Not found
newArchEnabled: Not found

info React Native v0.75.3 is now available (your project is running on v0.74.5).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.75.3
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.74.5
info For more info, check out "https://reactnative.dev/docs/upgrading?os=windows".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant