簡體   English   中英

未捕獲的語法錯誤:請求的模塊“https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js”未提供名為“default”的導出

[英]Uncaught SyntaxError: The requested module 'https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js' does not provide an export named 'default'

我正在嘗試為我正在開發的 web 應用程序設置和測試谷歌身份驗證。 我在運行 javascript 函數時遇到了很多問題,我不知道為什么。 我使用所有 CDN 導入,因為我在本地引用 firebase 文件夾時出錯。 這是我的文件:

firebase-config.js

// Import the functions you need from the SDKs you need
import firebase from "https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js"; 
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-analytics.js";

const firebaseConfig = {
 [config keys]
};

// Initialize Firebase app
const fb_app = firebase.initializeApp(firebaseConfig); // returns an app 
const analytics = getAnalytics(app);
export {fb_app};

登錄.js

import {fb_app} from "/src/firebase-config.js";

import { getAuth, signInWithPopup, GoogleAuthProvider } from "https://www.gstatic.com/firebasejs/9.4.0/firebase-auth.js";

fb_app; // I was getting an error that the firebase app isn't initialized, so I placed this here to see if it was work. I am not sure this is the correct way to call the app in this file. 

const auth = getAuth();
const provider = new GoogleAuthProvider(); 

signInWithPopup(auth, provider)
  .then((result) => {
    console.log("Signing User In...");
    // This gives you a Google Access Token. You can use it to access the Google API.
    const credential = GoogleAuthProvider.credentialFromResult(result);
    const token = credential.accessToken;
    // The signed-in user info.
    const user = result.user;
    // ...
  }).catch((error) => {
    // Handle Errors here.
    const errorCode = error.code;
    const errorMessage = error.message;
    // The email of the user's account used.
    const email = error.email;
    // The AuthCredential type that was used.
    const credential = GoogleAuthProvider.credentialFromError(error);
    // ...
  });
document.getElementById("signInButton").onclick = signInWithPopup(auth, provider); // this is how I am importing the function to the html. 

索引.html

<body>
        <div class="loginbox">
            <h1>Login</h1>
            <form>
                <div id="google-signin"> 
                    <button id="signInButton">Login with Google -></button>
                </div>
            </form>
        </div>
        <!-- <script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
        <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
        <script src="/src/signin.jsx"></script> -->
    </body>

任何幫助將不勝感激。 我對學習這些東西很陌生,所以我理解我是否可能無意中做錯了什么。 我收到了很多與較小的小細節有關的不同錯誤,但我真的不明白為什么會出現這個錯誤。 先感謝您。

您需要有關您正在使用的庫的更多詳細信息。 錯誤源自這里

import firebase from "https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js"; 

您正在嘗試通過不使用括號導入從庫中導入default object。 firebase 庫沒有提供。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM