Firebaseのimportについて。

前提

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メソッドは使用が出来ず、困っています。

&#12391;&#35501;&#12415;&#36796;&#12416;&#22580;&#21512;&#12289;&#12393;&#12385;&#12425;&#12418;&#20351;&#29992;&#12377;&#12427;&#12371;&#12392;&#12399;&#19981;&#21487;&#33021;&#12394;&#12398;&#12391;&#12375;&#12423;&#12358;&#12363;&#65311;&#65311; &#12414;&#12383;&#12289;firebase&#12399;&#26368;&#36817;&#20351;&#29992;&#12375;&#22987;&#12417;&#12383;&#32773;&#12391;&#12377;&#12398;&#12391;&#12289;&#31169;&#33258;&#36523;&#12398;&#35492;&#12426;&#12364;&#12354;&#12426;&#12414;&#12375;&#12383;&#12425;&#25945;&#12360;&#12390;&#12356;&#12383;&#12384;&#12369;&#12414;&#12375;&#12383;&#12425;&#24184;&#12356;&#12391;&#12377;&#12290; &#20309;&#21330;&#12424;&#12429;&#12375;&#12367;&#12362;&#39000;&#12356;&#12356;&#12383;&#12375;&#12414;&#12377;&#12290;

コメントを投稿

0 コメント