【问题标题】:unexpected token export firebase-app.js:1590意外令牌导出 firebase-app.js:1590
【发布时间】:2021-09-11 22:45:42
【问题描述】:

我第一次尝试firebase web,我一直在关注文档,但代码仍然不起作用,并在控制台中给出了这个“意外令牌\'export\'\”错误。 代码:

<!DOCTYPE html>
<html>
<head>
    <title> Firebase Demo </title>
    <script src=\"https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js\"/>
    <script src=\"https://www.gstatic.com/firebasejs/9.0.2/firebase-auth.js\"/>
    <script src=\"https://www.gstatic.com/firebasejs/9.0.2/firebase-database.js\"/>
    <script>
        const firebaseConfig = {
          #firebase config info
        };

        // Initialize Firebase
        const app = firebase.initializeApp(firebaseConfig);

        const database = firebase.database();
        database.ref(\"List/\"+\"Targets\").set({
            name:\"niel\",
            state:\"alive\"
        });
    </script>
</head>
<body>
<h1 align=\"center\">Firebase Jinx</h1>
</body>
</html>

请帮忙,谢谢

  • export 仅在模块中有效。使用&lt;script type=\"module\"&gt; 导入模块。

标签: javascript firebase-realtime-database


【解决方案1】:

默认情况下,v9 SDK 以 JavaScript 模块的形式提供。要在常规 JavaScript 导入中使用它们,并使用您的代码风格,您可以导入兼容层,如 using the compat library from your window 上的文档中所示:

<script src="https://www.gstatic.com/firebasejs/9.0.2/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.2/firebase-firestore-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.2/firebase-auth-compat.js"></script>

【讨论】:

    猜你喜欢
    • 2016-04-27
    • 2021-05-24
    • 1970-01-01
    • 2017-03-05
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    相关资源
    最近更新 更多