Javascript (索引):36未捕获类型错误:firebase.auth不是函数

Javascript (索引):36未捕获类型错误:firebase.auth不是函数,javascript,html,firebase,firebase-authentication,Javascript,Html,Firebase,Firebase Authentication,index.html代码 <html> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorig

index.html代码

<html>
    <head>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
        <script src="http://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script>
        <link rel="stylesheet" href="css/style.css" />
        <script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-app.js"></script>
        <script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-analytics.js"></script>
        <script defer src="https://www.gstatic.com/firebasejs/7.14.6/firebase-auth.js"></script>

    </head>
    <body class="bg-dark">
        <div id="login-card" class="card">
            <div class="card-body">
                <h1>Wallpaper App Admin</h1>

                <form id="login-form">
                    <div class="form-group">
                        <label for="email">Email</label>
                        <input type="email" id="email" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="password">Password</label>
                        <input type="password" id="password" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-primary" id="btn-login">Login</button>
                    </div>
                </form>
            </div>
        </div>

        <script src="js/app.js"></script>

        <script>
            firebase.auth().onAuthStateChanged(function(user) {
                if (user) {
                    window.location.href = "admin.html";
                } else {
                    // No user is signed in.
                }
            });
        </script>
    </body>

</html>
这里我使用Firebase身份验证登录方法作为电子邮件/密码。在Firebase控制台中,我启用了它。我已经在firebase控制台中保存了一个用户。但是我有一个这样的错误,所以我的网站不能正常工作。 这就是错误所在

(index):36 Uncaught TypeError: firebase.auth is not a function
    at (index):36
它将这一行显示为错误行,但我不理解为什么

firebase.auth().onAuthStateChanged(function(user) {

在这里,我对这条线有一些问题。代码行与firebase文档中的代码行相同,但不起作用。我正在使用可视代码作为编写此代码的工具。

从firebase auth脚本的脚本标记中删除延迟。这将导致仅在您的代码需要它之后才加载它

<script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-auth.js"></script>


阅读。

太好了!在堆栈溢出时,如果答案有帮助,通常会使用左侧的按钮向上投票并将答案标记为正确。
<script src="https://www.gstatic.com/firebasejs/7.14.6/firebase-auth.js"></script>