1

I'm running into an issue when trying to test Firestore and Storage rules locally using the Firebase Emulator Suite. I receive the following error:

⚠  Unexpected rules runtime error: java.lang.IllegalArgumentException: Path segment cannot be empty
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:151)
    at com.google.firebase.rules.runtime.utils.PathUtils.parse(PathUtils.java:129)
    ...
Error: Failed to send Cloud Storage rules request due to rules runtime not available.
error Command failed with exit code 1.

I'm trying to emulate Firestore and Cloud Storage with the following setup: firebase.json:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": "npm --prefix \"$RESOURCE_DIR\" run build",
    "source": "functions",
    "runtime": "nodejs20"
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "firestore": {
      "port": 8080
    },
    "functions": {
      "port": 5003
    },
    "storage": {
      "port": 9199
    },
    "ui": {
      "enabled": true,
      "port": 4000
    },
    "singleProjectMode": true
  },
  "storage": {
    "rules": "storage.rules"
  }
}

Firestore Rules (firestore.rules):

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /partners/{partnerID}/documents/{documentID} {
      allow read: if request.auth != null;
    }

    function canAccessPartner(partnerID) {
      return partnerID in request.auth.token.partners;
    }

    match /partners/{partnerID} {
      allow get, update: if canAccessPartner(partnerID);
    }
    
    // other rules...
  }
}

Storage Rules (storage.rules):

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

Problem: When I run my backend node.js I encounter the error Path segment cannot be empty when i try to use my frontend. It seems like the error is being thrown when deploying or testing rules, but I can't figure out where an empty path is being generated. I'm using the Firebase Emulator Suite for local testing, and the UI is enabled on port 4000. Additionally, I get this error: Error: read EIO, which might be related to Node.js or emulator issues.

What I Tried: Verified that all path segments ({partnerID}, {documentID}) are not empty in my Firestore and Storage rules. Reinstalled node_modules and cleaned the cache, thinking it could be a local environment issue. Tried using both Node.js v18 (LTS) and v20 to see if it was a Node version compatibility issue. Ran the emulator with detailed logs, but I couldn't find any specific Firestore or Storage requests causing the issue.

Question: What could be causing this "Path segment cannot be empty" error in my Firebase Emulator setup, and how can I debug or resolve this issue? Is there anything wrong with my Firestore or Storage rules that could be triggering this error? Could the issue be related to the emulator configuration or Node.js version? Any help or insights would be greatly appreciated!

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.