[英]How to fix this bug ? Unexpected SyntaxError: Unexpected token '!'
So basically the console is showing me that I have an unexpected token but I don't think there is any unexpected token.所以基本上控制台向我显示我有一个意外的令牌,但我认为没有任何意外的令牌。 Please help me.
请帮我。 I have taken way too much time trying to fix this problem.
我花了太多时间试图解决这个问题。 Here is the code -
这是代码 -
import React from 'react';
import firebase from 'firebase';
export default function App() {
// I have deleted this information because I don't want anyone to access my data
const firebaseConfig = {};
firebase.initializeApp(firebaseConfig);
function signInWithGoogle() {
var google_provider = new firebase.auth.GoogleAuthProvider();
firebase
.auth()
.signInWithPopup(google_provider)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.log(error);
});
}
return (
<div>
<h1>Google Sign In Authentication</h1>
<button onClick={signInWithGoogle}>Sign In</button>
</div>
);
}
The only issue I see in the provided code is you have not imported the Firebase Auth SDK. You can import that as shown below:我在提供的代码中看到的唯一问题是您没有导入 Firebase Auth SDK。您可以导入它,如下所示:
import firebase from 'firebase';
import "firebase/auth"
Also make sure you are using V8.XX
or lower with above code.还要确保您使用的是
V8.XX
或更低版本的上述代码。 If you have new Modular SDK V9.0.0+
then change your imports to compat version to keep using existing code:如果您有新的 Modular SDK
V9.0.0+
,则将导入更改为兼容版本以继续使用现有代码:
import firebase from 'firebase/compat/app';
import "firebase/compat/auth"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.