13

When I run firebase emulators:start I have this error

Error: Cannot start the Storage emulator without rules file specified In firebase.json

Before installing Storage emulator, I can set the rule for Firestore like this

{
  "firestore": {
    "rules": "./functions/firestore.rules"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "functions": {
      "port": 5001
    },
    "firestore": {
      "port": 8080
    },
    "storage": {
      "port": 9199
    },
    "ui": {
      "enabled": true
    }
  }
}

I believe I have to set the rule for storage in here. But I don't know how. I can't find the docs for this

Zoe
  • 27,060
  • 21
  • 118
  • 148
Alexa289
  • 8,089
  • 10
  • 74
  • 178

1 Answers1

35

The error you're seeing is caused by a missing storage rules file. The solution is very similar to the way you set rules for Firestore.

  1. Create a file called storage.rules in the same directory as firebase.json.
  2. Add the following lines to it:
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}
  1. Specify the rules file for the storage emulator in your firebase.json:
"emulators": {
  "storage": {
    "port": 9199,
    "rules": "storage.rules"
  },
}

Now, it's ready to start emulators.

Update

Thank you everyone for warning about the change in the newer versions. With the latest version, storage.rules should be defined at the top level in your firebase.json:

"emulators": {
  "storage": {
    "port": 9199
  },
},
"storage": {
  "rules": "storage.rules"
}
Stewie Griffin
  • 4,690
  • 23
  • 42
  • 11
    With the latest version I had to place `storage/rules` not within `emulators/storage`, but at the top level in `firebase.json`. – Peter Koltai Sep 01 '21 at 16:35
  • @PeterKoltai I also needed to do that. Thanks. – Vishal Kumar Sep 02 '21 at 01:09
  • 2
    For me the "rules": "storage.rules" entry had to be placed in the top level place in the firebase.json file, not within the "emulators" entry but in the "storage" – Dodi Jan 14 '22 at 08:54