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

NativeAnimatedModule causes "Invariant Violation: new NativeEventEmitter() requires a non-null argument." #2301

Closed
AdrianFahrbach opened this issue Dec 3, 2024 · 4 comments · Fixed by #2302
Labels
bug Something isn't working Needs: Triage 🔍

Comments

@AdrianFahrbach
Copy link

AdrianFahrbach commented Dec 3, 2024

Environment

react-native: v0.76.3
react-native-macos: v0.76.2
node: v20.12.1
xcodebuild -version: Xcode 16.1 Build version 16B40

Steps to reproduce the bug

  1. Clone our Chronos app repo
  2. Install all dependencies and start the project
  3. You should see this js error when the application start:
Invariant Violation: `new NativeEventEmitter()` requires a non-null argument.

Additional context

I'm coming from v0.75.9 (it is working fine in that version) and this can be reproduced with v0.76.0 as well.
Now I'm using v0.76.2 although there is an issue with an unavailable package (see issue #2282). I'm bypassing this issue with this overwrite:

"overrides": {
    "@react-native-mac/virtualized-lists": "0.76.0"
  }

I already did a bit of digging by adding console logs to the constructors in the node_modules and noticed that the native module that is null is NativeAnimatedModule. This can be nailed down to line 433 in node_modules/react-native-macos/src/private/animated/NativeAnimatedHelper.js:

export default {
  API,
  generateNewNodeTag,
  generateNewAnimationId,
  assertNativeAnimatedModule,
  shouldUseNativeDriver,
  transformDataType,
  // $FlowExpectedError[unsafe-getters-setters] - unsafe getter lint suppression
  // $FlowExpectedError[missing-type-arg] - unsafe getter lint suppression
  get nativeEventEmitter(): NativeEventEmitter {
    if (!nativeEventEmitter) {
      // $FlowFixMe[underconstrained-implicit-instantiation]
      nativeEventEmitter = new NativeEventEmitter(
        // T88715063: NativeEventEmitter only used this parameter on iOS. Now it uses it on all platforms, so this code was modified automatically to preserve its behavior
        // If you want to use the native module on other platforms, please remove this condition and test its behavior
        Platform.OS !== 'ios' ? null : NativeAnimatedModule, // <-- This is line 433
      );
    }
    return nativeEventEmitter;
  },
};

Removing the if/else statement and always returning NativeAnimatedModule fixes the issue.
It also seems like this file is not present in v0.75.9.

Is this fix maybe already a solution that I can use until the actual fix is released?


I also had issues with the Picker component from @react-native-picker/picker before. It was used in a .windows.tsx and was causing an error because of a missing macOS version (which it doesn't need, because it is only used in a .windows file and not anywhere else).
Maybe this is related to this issue, probably not though.

@AdrianFahrbach AdrianFahrbach added the bug Something isn't working label Dec 3, 2024
@Saadnajmi
Copy link
Collaborator

Saadnajmi commented Dec 3, 2024

The fix is the patch that you can see here (thanks @tido64 for helping find it), I need to go update RNM 0.76 and main with it expo/orbit#225

@AdrianFahrbach
Copy link
Author

Awesome! Thank you very much for the quick response!

@Saadnajmi
Copy link
Collaborator

#2302 and back ports will address

@gaeldestrem
Copy link

I also bumped in this issue because https://github.com/fivecar/react-native-draglist depends on NativeAnimatedModule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs: Triage 🔍
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants