Uncaught SyntaxError: The requested module 'https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js' does not provide an export named 'default'
Uncaught SyntaxError: The requested module 'https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js' does not provide an export named 'default'
我正在尝试为我正在使用的网络应用程序设置和测试 google 身份验证。我在获取 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};
signin.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.
index.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
对象。 firebase 库中没有提供。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
我正在尝试为我正在使用的网络应用程序设置和测试 google 身份验证。我在获取 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};
signin.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.
index.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
对象。 firebase 库中没有提供。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import