Google-signin: TypeError: Cannot read property 'SIGN_IN_CANCELLED' of undefined in React Native Web

Created on 31 May 2020  路  7Comments  路  Source: react-native-google-signin/google-signin

Steps to Reproduce

Install the module using npm on an Expo app

Type expo start -w to start React Native Web

Expected Behavior

App will build as GoogleSignIn is not used

Actual Behavior

Error message -

Screen Shot 2020-05-31 at 2 26 51 AM

Environment

React Native .61, google-signin version is 4.0.3

馃敠 Help Wanted

All 7 comments

This appears to be related to RNGoogleSignin being undefined on the web.

I'm not sure if there's a webpack/babel way to ignore this module (there may be, I am somewhat inexperienced with them), however at least one workaround I was able to get to work (a bit hacky, but it at least lets an app build) is to include two empty files:

GoogleSignin.web.js and GoogleSigninButton.web.js

Unless a better solution exists, or the module eventually supports a web version, I think that adding these files is a decent "fast" solution for projects that include the web.

I'm strugling with the same problem. The only difference this occurs in my built android app as well. Basically my app crashes on all platforms just because I write this line into my code:
import { GoogleSignin } from '@react-native-community/google-signin';

Ok, since this was ranked higher in Google, I post here where to search the solution:
https://www.google.com/url?q=https://docs.expo.io/versions/latest/sdk/google-sign-in/

If anyone else comes here first...

@haveamission That workaround will trigger other error

Screenshot from 2020-10-21 18-17-26

The error in web is because RNGoogleSignin is undefined.

https://github.com/react-native-google-signin/google-signin/blob/master/src/GoogleSignin.js#L3

export const statusCodes = {
  SIGN_IN_CANCELLED: RNGoogleSignin.SIGN_IN_CANCELLED,
  IN_PROGRESS: RNGoogleSignin.IN_PROGRESS,
  PLAY_SERVICES_NOT_AVAILABLE: RNGoogleSignin.PLAY_SERVICES_NOT_AVAILABLE,
  SIGN_IN_REQUIRED: RNGoogleSignin.SIGN_IN_REQUIRED,
};

@Bubuskac

https://github.com/expo/expo/issues/6884 GoogleSignIn will be deprecated in favor of expo-auth-session

An the way that expo-auth-session solved is:

https://github.com/expo/expo/blob/master/packages/expo-auth-session/src/providers/Google.ts

They use directly the google API for iOS, Android, and Web.

is this something in the priority for the team?

Actually I think this is not an issue if you use expo to build your app. Expo app should should expo-google-sign-in package instead of this one. This is not intended to use in expo. If you build without expo, then this is a problem.

I'm using:

"expo": "~41.0.1",
"@react-native-google-signin/google-signin": "^6.0.1",
"react-native": "~0.64.2",
"@robinbobin/react-native-google-drive-api-wrapper": "^0.6.0",

And at my first build I received:

 ERROR  TypeError: Cannot read property 'SIGN_IN_CANCELLED' of null, js engine: hermes
 ERROR  Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes

In this case the the registerRootComponent from Expo, which uses AppRegistry from React Native was failing to link the library, so I just removed the dependencies node_module and it worked. Not sure if this helps anyone, but...

Was this page helpful?
0 / 5 - 0 ratings