はじめに
firebase emulators:start
を実行して、エミュレーターを初めて起動した時にCloud Storageに関するエラーに遭遇した。
Error: Cannot start the Storage emulator without rules file specified in firebase.json: run 'firebase init' and set up your Storage configuration
Firebaseコンソール上でのCloud Storageの未設定によるエラー
とりあえず、firebase init
を実行してCloud Storage
の設定を追加しようとした。
? Which Firebase features do you want to set up for this directory? Press Space to select features, then Enter to confirm your choices. (Pres
s <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
◯ Functions: Configure a Cloud Functions directory and its files
◯ Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys
◯ Hosting: Set up GitHub Action deploys
❯◉ Storage: Configure a security rules file for Cloud Storage
◯ Emulators: Set up local emulators for Firebase products
◯ Remote Config: Configure a template file for Remote Config
◯ Realtime Database: Configure a security rules file for Realtime Database and (optionally) provision default instance
(Move up and down to reveal more choices)
またエラーが出た。
Cloud resource location is not set for this project but the operation you are attempting to perform in Cloud Storage requires it. Please see this documentation for more details: https://firebase.google.com/docs/projects/locations
FirebaseコンソールでCloud Storageを設定
Firebaseコンソールで、Storageのページを開いて「はじめる」をクリックする。
とりあえず、テストモードを選択して次へ進む。
ロケーションを選択して完了をクリックする。
次のような画面が表示された完了。
storage.rulesファイルを作成
FirebaseコンソールでCloud Storageの設定後、firebase init
を再度実行した。
そのままエンターキーを押下して、ルートディレクトリにstorage.rules
を作成した。
=== Storage Setup
Firebase Storage Security Rules allow you to define how and when to allow
uploads and downloads. You can keep these rules in your project directory
and publish them with firebase deploy.
? What file should be used for Storage Rules? storage.rules
✔ Wrote storage.rules
i Writing configuration info to firebase.json...
i Writing project information to .firebaserc...
✔ Firebase initialization complete!
これで問題なくFirebaseエミュレーターを起動できる。