前提
Javascriptの<script>タグを用いて、Firebaseと連携をしようとした際にエラーが発生しました。
実現したいこと
Database(RealtimeDatabase)内のデータ取得と、FireStorage(保存した画像の取得)の両方を利用したい。
⇒両方で"ref"のimportが必要だと、認識しています。
発生している問題・エラーメッセージ
Uncaught SyntaxError: Identifier 'ref' has already been declared (at index.php:24:30)
該当のソースコード
Javascript
<!--Firebase--> <script type="module"> // Import the functions you need from the SDKs you need import { initializeApp } from "https://www.gstatic.com/firebasejs/9.9.4/firebase-app.js"; import { getDatabase,ref, push, set, onChildAdded, remove, onChildRemoved } from "https://www.gstatic.com/firebasejs/9.9.4/firebase-database.js"; import { getStorage, ref, getDownloadURL } from "https://www.gstatic.com/firebasejs/9.9.4/firebase-storage.js"; // TODO: Add SDKs for Firebase products that you want to use // https://firebase.google.com/docs/web/setup#available-libraries // Your web app's Firebase configuration const firebaseConfig = { …以降つづく
試したこと
refを2つ読み込むことでエラーが発生していると考え、
firebase-database.js と firebase-storage.js のどちらかのrefを削除すると、エラーが消えて、正常に動作する。
しかし、当然消した方のrefメソッドは使用が出来ず、困っています。
0 コメント