5

I'm trying to deploy a project with firebase init. When I get to the part that asks me this: "What file should be used for Realtime Database Security Rules? database.rules.json", I press enter and an error appears:

Error: Unable to parse JSON: SyntaxError: Unexpected token } in JSON at position 540

What should I do? Help pls.

3
  • What does database.rules.json look like? Commented Jun 2, 2022 at 0:09
  • when prompt with database file name use database.rules , and remove .json extension Commented Jun 2, 2022 at 10:05
  • you need to remove Comments // These rules grant access to a node matching the authenticated // user's ID from the Firebase auth token in your FIrebase Realtime Database rules, apparently Comments are not permitted in JSON. Commented Jun 8, 2022 at 4:55

1 Answer 1

2

Using the --debug argument I've found out that if there isn't a database.rules.json file in the init directory, it will automatically copy what is online in the project. But here's the problem: If the database hast been initialized yet, it will return invalid json (since the rules haven't been setup yet).

So here's how to fix:

  • Create your own database.rules.json file in your project directory and configure it with valid json.
{
    "rules": {
        ".read": true,
        ".write": false
    }
}
  • When you run firebase init and get to the part where it asks you What file should be used for Realtime Database Security Rules? use the already created file (so usually just 'database.rules.json').
  • If you pointed to the correct file it will ask you File database.rules.json already exists. Do you want to overwrite it with the Realtime Database Security Rules for insektenhotel-default-rtdb f rom the Firebase console? (This is automatically yes if the files doesn't exist, causing the problem). Say No.

It should work now.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.