1
votes

Error: On any change of firestore.rules, Firestore emulator output:

i  firestore: Change detected, updating rules...
**⚠  firestore.rules:0:0 - ERROR Rules content empty. Compilation aborted.**
✔  firestore: Rules updated.

Platforms tried: WSL as well as an Ubuntu VM under virtualbox

Codelab: https://google.dev/codelabs/firebase-emulator-test-rules

Current firestore.rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /carts/{cartID} {
      allow create: if request.auth.uid == request.resource.data.ownerUID;
      allow read, update, delete: if request.auth.uid == resource.data.ownerUID;
    }
    match /carts/{cartID}/items/{itemID} {
      allow read, write: if get(/databases/$(database)/documents/carts/$(cartID)).data.ownerUID == request.auth.uid;
    }
    match /items/{itemID} {
      allow read; // Users can read items
      // In a production app, don't allow unconditional write access!
      allow create; // For the codelab, client app uses this to add seed data.
    }
  }
}

Project Configuration on Firebase console: Only two modifications were made to the default project, enable anonymous auth (per codelab), and add firestore in production mode.

... I've googled for this "firestore.rules:0:0 - ERROR Rules content empty. Compilation aborted." error, but nothing comes up. Anybody else see this?

2
Out of curiosity, have you tried dropping rules_version = '2'; from the beginning? My theory is it's a bug that the emulator doesn't recognize that instruction. - samthecodingman

2 Answers

0
votes

That error suggests to me that your code is trying to load a file that's empty. Check that you your configuration pointing to the correct file, and be sure to save the file in your text editor to make sure it contains the content you expect.

0
votes

My experience is that this is a bug in the emulator. While testing rules changes (or unit test changes) over and over again, I sometimes get this error. If I do, all future rules changes appear to be ignored. Very strange.

Sadly, my current workaround is to stop and restart the emulators. Things will then start to work as expected.

If someone has a different solution, I would love to hear it!