Getting error while using Expo sdk for Google Expo.Google.logInAsync

While following the Expo sdk for Google to login using google account, I got the following error.

undefined is not an object (evaluating ‘_expo.default.Google’)

  • screens/LoginScreen.js:15:32 in _callee$
  • node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch

  • node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:30 in invoke

  • node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch

  • node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:28 in invoke

  • node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:17 in

  • node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo

  • node_modules/promise/setimmediate/core.js:200:23 in doResolve

  • node_modules/promise/setimmediate/core.js:66:12 in Promise

  • node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:169:27 in callInvokeWithMethodAndArg

  • node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:192:38 in enqueue

  • node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:216:8 in async

  • screens/LoginScreen.js:13:26 in _callee

  • screens/LoginScreen.js:43:23 in onPress

  • node_modules/react-native/Libraries/Components/Touchable/TouchableOpacity.js:235:45 in touchableHandlePress

  • node_modules/react-native/Libraries/Components/Touchable/Touchable.js:878:34 in _performSideEffectsForTransition

  • … 21 more stack frames from framework internals

package.json
{
“main”: “node_modules/expo/AppEntry.js”,
“scripts”: {
“start”: “expo start”,
“android”: “expo start --android”,
“ios”: “expo start --ios”,
“web”: “expo start --web”,
“eject”: “expo eject”
},
“dependencies”: {
“expo”: “^33.0.0”,
“firebase”: “^6.2.0”,
“react”: “16.8.3”,
“react-dom”: “^16.8.6”,
“react-native”: “https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz”,
“react-native-elements”: “^1.1.0”,
“react-native-web”: “^0.11.4”,
“react-navigation”: “^3.11.0”
},
“devDependencies”: {
“babel-preset-expo”: “^5.1.1”
},
“private”: true
}

LoginScreen.js

import React, { Component } from ‘react’;
import { View, Text, StyleSheet } from ‘react-native’;
import { Button } from ‘react-native-elements’;
import Expo from ‘expo’;

class LoginScreen extends Component {
constructor(props) {
super(props);
this.state = {
};
}

signInWithGoogleAsync = async () => {
try {
const result = await Expo.Google.logInAsync({
behavior: ‘web’,
androidClientId: ‘xxxxxxx’,
iosClientId: ‘xxxx’,
scopes: [‘profile’, ‘email’],
});
if (result.type === ‘success’) {
return result.accessToken;
} else {
console.log(‘inside else’)
return { cancelled: true };
}
} catch (e) {
console.log(e)
return { error: true };
}
}

login = () => {
console.log(‘inside login’)
}

render() {
return (

<Button
title=“Login with Google”
type=‘clear’
onPress={() => this.signInWithGoogleAsync()}
/>

);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: ‘center’,
justifyContent: ‘center’
}
})

export default LoginScreen;

We’ve updated the import syntax- you can find the correct one in the docs

Just used import { Google } from "expo"; in a test project and it worked

Let me know if that doesn’t work!

Thanks for quick reply, It worked

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.