react-native-datetimepicker / datetimepicker

React Native date & time picker component for iOS, Android and Windows
MIT License
2.5k stars 402 forks source link

undefined is not an object (evaluating '_datetimepicker.DateTimePickerAndroid.open' (android) #666

Closed AchrafBn closed 1 year ago

AchrafBn commented 2 years ago

I display DateTimePicker using the imperative API , it was working before , and today it throws the following error

`TypeError: undefined is not an object (evaluating '_datetimepicker.DateTimePickerAndroid.open')
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-dev-launcher/build/DevLauncherErrorManager.js:44:19 in errorHandler
at node_modules/expo-dev-launcher/build/DevLauncherErrorManager.js:49:24 in <anonymous>
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:8:32 in ErrorUtils.setGlobalHandler$argument_0
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError`

Code

import DateTimePicker, {
  DateTimePickerAndroid,
} from "@react-native-community/datetimepicker";

 const handleShowPicker = (f: string) => {
      DateTimePickerAndroid.open({
        themeVariant: "dark",
        value:new Date()
        mode: "date",
        display: "spinner",
        onChange: (event, date) => handleDateOnChange(event, date, f),
      });
  };

       <Box>
                   <TextLink

                  onPress={() => {
                    handleShowPicker();
                  }}
                TextLink/>
</Box>

And EsLint show error when Importing "DateTimePickerAndroid" Module '"@react-native-community/datetimepicker"' has no exported member 'DateTimePickerAndroid'. Did you mean to use 'import DateTimePickerAndroid from "@react-native-community/datetimepicker"' instead?ts(2614)

I tried to upgrade to latest version but expo keep showing warning

Some dependencies are incompatible with the installed expo package version:
 - @react-native-community/datetimepicker - expected version: 4.0.0 - actual version installed: 6.4.0

Expo info

  expo-env-info 1.0.5 environment info:
    System:
      OS: macOS 11.2.3
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 14.15.3 - ~/.nvm/versions/node/v14.15.3/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 8.9.0 - ~/.nvm/versions/node/v14.15.3/bin/npm
    Managers:
      CocoaPods: 1.11.3 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
      Android SDK:
        API Levels: 29, 30, 31, 32
        Build Tools: 29.0.2, 30.0.0, 30.0.2, 31.0.0
        System Images: android-29 | Intel x86 Atom_64, android-30 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 2020.3 AI-203.7717.56.2031.7678000
      Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
    npmPackages:
      expo: ^44.0.4 => 44.0.4
      react: 17.0.1 => 17.0.1
      react-dom: 17.0.1 => 17.0.1
      react-native: 0.64.3 => 0.64.3
      react-native-web: 0.17.1 => 0.17.1
    npmGlobalPackages:
      eas-cli: 0.54.1
      expo-cli: 6.0.6
    Expo Workflow: bare

Package.json

  "dependencies": {
    "@expo/react-native-action-sheet": "^3.13.0",
    "@expo/vector-icons": "^12.0.0",
    "@react-native-async-storage/async-storage": "~1.15.0",
    "@react-native-community/datetimepicker": "4.0.0",
    "@react-native-community/hooks": "^2.8.1",
    "@react-navigation/bottom-tabs": "^6.0.9",
    "@react-navigation/native": "^6.0.6",
    "@react-navigation/native-stack": "^6.2.5",
    "axios": "^0.25.0",
    "dayjs": "^1.10.7",
    "dayjs-recur": "^1.0.1",
    "expo": "^44.0.4",
    "expo-app-loading": "~1.3.0",
    "expo-asset": "~8.4.6",
    "expo-auth-session": "~3.5.0",
    "expo-blur": "~11.0.0",

}
vonovak commented 2 years ago

Hello and thanks for reporting, did you check in node_modules if the DateTimePickerAndroid.open method is there? I guessing that the problem is that you're probably using a very old version. I recommend you upgrade to the latest version (you can use expo prebuild) and make sure that the method you're calling exists in the sources. Thank you 🙂