Description
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
- Clone our Chronos app repo
- Install all dependencies and start the project
- 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.