Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON parsing error when running firebase init #4616

Closed
thephfernandes opened this issue Jun 5, 2022 · 5 comments
Closed

JSON parsing error when running firebase init #4616

thephfernandes opened this issue Jun 5, 2022 · 5 comments

Comments

@thephfernandes
Copy link

thephfernandes commented Jun 5, 2022

[REQUIRED] Environment info

firebase-tools: 11.0.1

Platform: Windows

[REQUIRED] Test case

  • Install firebase CLI
  • Run firebase init

[REQUIRED] Steps to reproduce

  • Run firebase init inside a project
  • When asked which features to automatically set up, select Firestore: Configure security rules and indexes files for Firestore
  • Enter the default filename for Realtime Database Security Rules (database.rules.json)

[REQUIRED] Expected behavior

A json document containing database rules will be written to the project.

[REQUIRED] Actual behavior

n JSON parsing error occurs.

Logs:
? What file should be used for Realtime Database Security Rules? database.rules.json

[2022-06-05T04:05:03.019Z] >>> [apiv2][query] GET https://<MY-APP>-default-rtdb.firebaseio.com/.settings/rules.json [none]

[2022-06-05T04:05:03.773Z] <<< [apiv2][status] GET https://<MY-APP>-default-rtdb.firebaseio.com/.settings/rules.json 200

[2022-06-05T04:05:03.773Z] <<< [apiv2][body] GET https://<MY-APP>-default-rtdb.firebaseio.com/.settings/rules.json
"{\n /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */\n \"rules\": {\n \".read\": false,\n \".write\": false\n }\n}"

Error: Unable to parse JSON: SyntaxError: Unexpected token / in JSON at position 4

@kdavong
Copy link

kdavong commented Jun 5, 2022

Hi,

When you actually use firebase init command, do you use an existing project? In this case, you should check your Realtime Database rules directly in your firebase console, because Firebase Init will try to copy it in local. Try to delete all comments in.

@thephfernandes
Copy link
Author

thephfernandes commented Jun 5, 2022

My realtime database rules looks like this:
image

Which matches the content of the request body posted in my original message

"{\n /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */\n \"rules\": {\n \".read\": false,\n \".write\": false\n }\n}"

But it seems escaping characters with \ isn't working properly after the response.

@kdavong
Copy link

kdavong commented Jun 5, 2022

Try to add an EOF in your json rules. (7th empty line)

@david-potgieter
Copy link

Workaround I used to get around this. Grab the Realtime DB rules from your console, and create a database.rules.json file manually locally. Remove the comments (as mentioned above) and ensure you have a well formed json and EOF.

Then run firebase init, and say N when prompted if you should overwrite the existing database.storage.rules. Rest of the init completes.

@bkendall
Copy link
Contributor

This should be resolved in v11.1.0 (which is going out today). Sorry for not getting the fix out sooner.

Duplicate #4596

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants