react-native-date-picker icon indicating copy to clipboard operation
react-native-date-picker copied to clipboard

Invariant Violation: `new NativeEventEmitter()` requires a non-null argument.

Open zihaolam opened this issue 1 year ago • 11 comments

Describe the bug ERROR Invariant Violation: new NativeEventEmitter() requires a non-null argument.

This error is located at: in DatePickerIOS (created by DatePickerWrapper) in DatePickerWrapper (created by BookSessionModal) in RCTView in Unknown (created by BookSessionModal) in BookSessionModal (created by ModalScreen) in ModalScreen in Unknown (created by Route(modal)) in Suspense (created by Route(modal)) in Route (created by Route(modal)) in Route(modal) (created by SceneView) in StaticContainer in EnsureSingleNavigator (created by SceneView) in SceneView (created by SceneView) in RCTView (created by View) in View (created by DebugContainer) in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer (created by DebugContainer) in DebugContainer (created by MaybeNestedStack) in RNSScreen (created by Animated(Anonymous)) in Animated(Anonymous) (created by InnerScreen) in Suspender (created by Freeze) in Suspense (created by Freeze) in Freeze (created by DelayedFreeze) in DelayedFreeze (created by InnerScreen) in InnerScreen (created by Screen) in Screen (created by MaybeNestedStack) in Suspender (created by Freeze) in Suspense (created by Freeze) in Freeze (created by DelayedFreeze) in DelayedFreeze (created by ScreenStack) in RNSScreenStack (created by ScreenStack) in ScreenStack (created by MaybeNestedStack) in MaybeNestedStack (created by SceneView) in RCTView (created by View) in View (created by SceneView) in RNSModalScreen (created by Animated(Anonymous)) in Animated(Anonymous) (created by InnerScreen) in Suspender (created by Freeze) in Suspense (created by Freeze) in Freeze (created by DelayedFreeze)

Expected behavior For the datepicker to render

To Reproduce

import React from "react";
import DatePicker from "react-native-date-picker";
import { View, Text } from "tamagui";

export const BookSessionModal = () => {
	const [isDatePickerOpen, setIsDatePickerOpen] = React.useState(false);
	const [selectedDate, setSelectedDate] = React.useState<Date>(new Date());
	return (
		<View>
			<Text>Book Session</Text>
			<DatePicker
				modal
				open={isDatePickerOpen}
				date={selectedDate}
				onConfirm={(date) => {
					setIsDatePickerOpen(false);
					setSelectedDate(date);
				}}
				onCancel={() => {
					setIsDatePickerOpen(false);
				}}
			/>
		</View>
	);
};

Smartphone (please complete the following information):

  • OS: iOS
  • React Native version 0.74.1
  • react-native-date-picker version ^5.0.4

zihaolam avatar Jun 13 '24 10:06 zihaolam

Are you running this in your unit test? I received the same error but only when running unit tests using Jest.

andydotdaniel avatar Jun 15 '24 05:06 andydotdaniel

Having the same problem.

  • React Native: 0.68.0

MarcosJBM avatar Jun 16 '24 01:06 MarcosJBM

@zihaolam @MarcosJBM I was having this issue too, FYI in my experience Invariant Violation: new NativeEventEmitter() bugs in RN seem to be caused by a pods/bundling mismatch between RN and native modules.

For me, updating my packages, updating pods and rebuilding for IOS fixed it:

  • npx expo install --fix (if using expo)
  • npx pod-install (reinstall pods)
  • npx expo run:ios (which re-builds for IOS)

jvgeee avatar Jun 17 '24 00:06 jvgeee

For jest add on setup file jest.mock('react-native-date-picker', () => 'DatePicker');

rocket13011 avatar Jun 19 '24 07:06 rocket13011

Any solution for this issue? The date picker works fine on Android but I get this error on iOS. I'm running RN 0.67 and React Native Date Picker ^5.0.4

btsungu avatar Jun 21 '24 07:06 btsungu

Going back go version 4.4.0 solved it for my team.

colingraydon avatar Jun 26 '24 20:06 colingraydon

on Expo running npx expo prebuild --clean solves the issue.

julekgwa avatar Jul 06 '24 16:07 julekgwa

Going back to v5.0.1 avoids the issue for now

fikkatra avatar Jul 10 '24 08:07 fikkatra

Any progress on this issue?

ryansherby avatar Aug 02 '24 04:08 ryansherby

hi, I'm having the same problem too

ysnbyzli avatar Aug 21 '24 18:08 ysnbyzli

For me with RN 67 v4.2.2 solved the issue.

btsungu avatar Aug 22 '24 01:08 btsungu

same issue for me any update?

 ERROR  Warning: Invariant Violation: `new NativeEventEmitter()` requires a non-null argument.

This error is located at:
    in DatePickerIOS (created by DatePickerWrapper)

img

ashirkhan94 avatar Dec 05 '24 10:12 ashirkhan94

Going back to v5.0.1 avoids the issue for now

I tried this, it got rid of the error but now the button is inactive. If anyone has any solutions, I have opened an issue, so you can reply there.

Linda2734 avatar Dec 05 '24 12:12 Linda2734

jvgeee

I tried this, it got rid of the error but now the button is inactive. If anyone has any solutions, I have opened an issue, so you can reply there.

Linda2734 avatar Dec 05 '24 12:12 Linda2734

You'll get this error if running in Expo Go (which it is documented will not work). If you are in expo, make sure you are using the development build.

iverok avatar Feb 06 '25 12:02 iverok

If someone is still seeing this issue with latest version, please let me know what version you are on and I will reopen.

(Also yes Expo Go is unsupported)

henninghall avatar Mar 22 '25 09:03 henninghall

"react-native-date-picker": "^5.0.13",

I have the same problem.

senerdude avatar Jun 13 '25 16:06 senerdude

Same issue is happening on Expo development builds with version :5.0.13 Expo SDK-52 and RN:0.76.9 @henninghall

rizikolik avatar Jun 29 '25 21:06 rizikolik

Anyone have a solution for this? I am also having problems with this error in Expo Development Build.

Picker: 5.0.13 Expo: 53.0.19

monkemedia avatar Jul 11 '25 11:07 monkemedia

I got it working with: "@react-native-community/datetimepicker": "^8.4.1" - using react native bareflow with expo just for preview, here is my code: import React from "react"; import { View, Platform } from "react-native"; import DateTimePicker from "@react-native-community/datetimepicker"; import { IMyDatePickerProps } from "../../types/components.types"; import React from 'react'; import { View, Platform, Modal, StyleSheet } from 'react-native'; import DateTimePicker from '@react-native-community/datetimepicker'; import CustomBtn from './CustomBtn'; import { IMyDatePickerProps } from '../../types/components.types';

const MyDatePicker: React.FC<IMyDatePickerProps> = ({ value = new Date(), onChange, mode = "date", minimumDate, maximumDate, open = false, onClose, }) => { const [iosDate, setIosDate] = React.useState(value);

const handleChange = (event: any, selectedDate?: Date) => { if (Platform.OS === 'android') { onClose?.(); if (selectedDate) { onChange?.(selectedDate); } return; }

// For iOS, we just update the temp date
if (selectedDate) {
  setIosDate(selectedDate);
}

};

const handleIosConfirm = () => { onChange?.(iosDate); onClose?.(); };

if (Platform.OS === 'web') { return null; } return ( <> {Platform.OS === 'ios' && open ? ( <Modal transparent animationType="slide"> <View style={styles.iosContainer}> <View style={styles.iosHeader}> <CustomBtn onPress={onClose} btnText="Cancel" variant="none" noBackground noBorder textStyle={styles.iosButtonText} /> <View style={{ flex: 1 }} /> <CustomBtn onPress={handleIosConfirm} btnText="Done" variant="none" noBackground noBorder textStyle={[styles.iosButtonText, styles.iosConfirmText]} /> </View> <View style={styles.iosPickerContainer}> <DateTimePicker value={iosDate} mode={mode} display="spinner" onChange={handleChange} minimumDate={minimumDate} maximumDate={maximumDate} themeVariant="light" /> </View> </View> </Modal> ) : open ? ( <DateTimePicker value={value} mode={mode} display="default" onChange={handleChange} minimumDate={minimumDate} maximumDate={maximumDate} /> ) : null} </> ); };

const styles = StyleSheet.create({ iosContainer: { flex: 1, justifyContent: 'flex-end', backgroundColor: 'rgba(0,0,0,0.5)', }, iosHeader: { flexDirection: 'row', alignItems: 'center', padding: 16, backgroundColor: '#f8f8f8', borderTopWidth: 1, borderTopColor: '#dedede', }, iosButtonText: { fontSize: 16, color: '#007AFF', paddingHorizontal: 8, }, iosConfirmText: { fontWeight: '600', }, iosPickerContainer: { backgroundColor: 'white', }, }); export default MyDatePicker; I have a custombtn using Pressable, my versions: "expo": "^53.0.19", "expo-dev-client": "~5.2.4", "react-native": "0.79.5", "react-native-date-picker": "^5.0.13",

I hope this helps anyone 👍

RolandExSauce avatar Jul 19 '25 13:07 RolandExSauce

Hi @henninghall, I'm seeing this with version 5.0.13 of react-native-date-picker, in a react-native cli project, react-native version 0.73.7.

wavesandwaves avatar Aug 13 '25 12:08 wavesandwaves