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

Failed to check or start update: [TypeError: Cannot read property 'checkNeedsUpdate' of null] #179

Open
UtkarshFSD opened this issue May 13, 2024 · 11 comments

Comments

@UtkarshFSD
Copy link

UtkarshFSD commented May 13, 2024

Don't know why but I'm getting this error
Although , I have installed it correctly & getting the inAppUpdates all props

import SpInAppUpdates, {
NeedsUpdateResponse,
IAUUpdateKind,
StartUpdateOptions,
} from "sp-react-native-in-app-updates"

SplashScreen.preventAutoHideAsync()

function IgniteApp() {
const inAppUpdates = new SpInAppUpdates(false)

const checkAndUpdateApp = async () => {
try {
console.log("Before checkNeedsUpdate:", inAppUpdates)
const result = await inAppUpdates.checkNeedsUpdate()
console.log("Update result:", result)

  if (result.shouldUpdate) {
    let updateOptions: StartUpdateOptions = {}

    if (Platform.OS === "android") {
      updateOptions = {
        updateType: IAUUpdateKind.IMMEDIATE,
      }
      await inAppUpdates.startUpdate(updateOptions)
    } else {
      console.log("Update available. Please visit the App Store to update the app.")
    }
  }
} catch (error) {
  console.error("Failed to check or start update:", error)
}

}

React.useEffect(() => {
async function onFetchUpdateAsync() {
try {
const update = await Updates.checkForUpdateAsync()

    if (update.isAvailable) {
      await Updates.fetchUpdateAsync()
      await Updates.reloadAsync()
    }
  } catch (error) {
    console.log("RTTTR", error)
    alert(`Error fetching latest Expo update: ${error}`)
  }
}
console.log("FFff-----", __DEV__)
if (!__DEV__) {
  onFetchUpdateAsync()
}
checkAndUpdateApp()

}, [])

@27ksandip
Copy link

same error
TypeError: Cannot read property 'displayName' of undefined, js engine: hermes
ERROR TypeError: Cannot read property 'checkNeedsUpdate' of null
any one can help ?

@SudoPlz
Copy link
Owner

SudoPlz commented Jun 2, 2024

this is interesting. Is this a vanilla react-native app? (iOS or Android)? I'm asking because this library is using .ios.ts or .android.ts file name extensions which metro bundler knows how to handle.
(I suspect that something on your environment may be different?)

@27ksandip
Copy link

27ksandip commented Jun 2, 2024

this is interesting. Is this a vanilla react-native app? (iOS or Android)? I'm asking because this library is using .ios.ts or .android.ts file name extensions which metro bundler knows how to handle. (I suspect that something on your environment may be different?)

@SudoPlz
I am using react native expo and try to add update feature (no typescript )

@malaiandrei
Copy link

i have the same problem
react-native@0.72.12
has anyone found a solution?

@lewismunene020
Copy link

i also have the same problem in expo
@SudoPlz what might the issue

@27ksandip
Copy link

@lewismunene020 @malaiandrei
You need to publish your app on the Play Store, and then it will be fixed automatically. If you debug in detail, you might see an error like "package name could not be found" or something similar. However, once the app is published, it works fine.

@lewismunene020
Copy link

the app is already on playstore currently so i guess the package name is present at the monent

@27ksandip
Copy link

the app is already on playstore currently so i guess the package name is present at the monent

is production released ?
if not you will face this issue

@lewismunene020
Copy link

so there is an app in production and am adding the feature into an existing app but i just keep getting the error

@27ksandip
Copy link

27ksandip commented Jul 15, 2024

useEffect(() => {
const init = async () => {
try {
const currentAppVersion = Constants.expoConfig.version;

    const check = await checkVersion({
      version: currentAppVersion,
      androidStoreURL:
        "enter_app_url: "np",
    });
    if (check.result === "new") {
      setIsUpdateAvailable(true);
    }
  } catch (e) {
    showMessage({
      message: "Something went wrong",
      type: "danger",
    });
  }
};

init();

}, []);

you can try this package
react-native-store-version
its working fine in my app
https://www.npmjs.com/package/react-native-store-version

@lewismunene020
Copy link

Thanks for that it has worked with this code

useEffect(() => {
    const init = async () => {
      try {
        if (Platform.OS === "android") {
          const check = await checkVersion({
            version: AppConfig.ios_app_version, // app local version
            iosStoreURL: AppConfig.iosUrl,
            androidStoreURL: AppConfig.playStoreUrl,
            country: "jp", // default value is 'jp'
          });

          if (check.result === "new") {
            // if app store version is new
            console.log("new version");
            Alert.alert(
              "New Version Available",
              "New version available! Please update the app to the latest version",
              [
                {
                  text: "Cancel",
                  onPress: () => console.log("Cancel Pressed"),
                  style: "cancel",
                },
                {
                  text: "Update",
                  onPress: () => {
                    console.log("OK Pressed");
                    // lets open  the  playstore app url on android
                    Linking.openURL(AppConfig.playStoreUrl);
                  },
                },
              ]
              // { cancelable: false }
            );
          } else {
            console.log("latest version");
          }
        } else {
          console.log("not android");
          console.log("ios updates coming  soon");
        }
      } catch (e) {
        console.log(e);
      }
    };

    init();
  }, []);
  
  
```
Thanks  for your advice .

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

5 participants