最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - unexpected token export firebase-app.js:1590 - Stack Overflow

programmeradmin1浏览0评论

I am trying firebase web for first time, i was following the documentation still code isn't working and giving this "unexpected token 'export' " error in console. code:

<!DOCTYPE html>
<html>
<head>
    <title> Firebase Demo </title>
    <script src=".0.2/firebase-app.js"/>
    <script src=".0.2/firebase-auth.js"/>
    <script src=".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>

please help, thank you

I am trying firebase web for first time, i was following the documentation still code isn't working and giving this "unexpected token 'export' " error in console. code:

<!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>

please help, thank you

Share Improve this question asked Sep 11, 2021 at 6:47 Bhushan PatilBhushan Patil 911 gold badge1 silver badge3 bronze badges 1
  • 4 export is only valid in modules. Modules are imported with <script type="module">. – Sebastian Simon Commented Sep 11, 2021 at 6:49
Add a comment  | 

1 Answer 1

Reset to default 20

The v9 SDKs are shipped as JavaScript modules by default. To use them in a regular JavaScript import, and to use your style of code, you can instead import the compatibility layer as shown in the documentation on 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>
发布评论

评论列表(0)

  1. 暂无评论