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

firebase init firestore not work with existing project #4254

Closed
JuanOrtizOvied opened this issue Mar 5, 2022 · 62 comments
Closed

firebase init firestore not work with existing project #4254

JuanOrtizOvied opened this issue Mar 5, 2022 · 62 comments

Comments

@JuanOrtizOvied
Copy link

DESCRIPTION

work very well with version 10.0.1

firebase login --no-localhost

**version 10.0.1 **

open https://accounts.google.com/o/oauth2....

** version 10.2.2 **

open https://auth.firebase.tools/login?code=....

[REQUIRED] Environment info

firebase-tools: 10.2.2

Platform: ubuntu 20

[REQUIRED] Test case

Screenshot at Mar 04 9-45-54 PM

[REQUIRED] Steps to reproduce

firebase login --no-localhost

firebase init firestore

[REQUIRED] Expected behavior

create firebase.rules file

[REQUIRED] Actual behavior

Error: It looks like you haven't used Cloud Firestore in this project before. Go to https://console.firebase.google.com/project/<PROJECT-ID>/firestore to create your Cloud Firestore database.
@yuchenshi
Copy link
Member

Have you enabled Cloud Firestore on your existing project before you tried this? If so, this is definitely a bug or a permission issue (and please let us know if you're using a non-Admin account or service account). If not, please follow the link which explains about setting up Firestore.

@yuchenshi yuchenshi added the Needs: Author Feedback Issues awaiting author feedback label Mar 7, 2022
@JuanOrtizOvied
Copy link
Author

Yes, I created my firestore database one month ago.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Mar 7, 2022
@bkendall
Copy link
Contributor

bkendall commented Mar 7, 2022

To confirm the type of issue, can you run the command with --debug and provide the last bit of output? It's likely there's an HTTP request that's returning some type of error or a check that's being made that's incorrect. Thanks!

@bkendall bkendall added Needs: Author Feedback Issues awaiting author feedback and removed Needs: Attention labels Mar 7, 2022
@JuanOrtizOvied
Copy link
Author

@bkendall

[2022-03-08T19:10:53.980Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[2022-03-08T19:10:53.980Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token  
 <request body omitted>
[2022-03-08T19:10:54.537Z] <<< HTTP RESPONSE 400 {"cache-control":"no-cache, no-store, max-age=0, must-revalidate","date":"Tue, 08 Mar 2022 19:10:54 GMT","expires":"Mon, 01 Jan 1990 00:00:00 GMT","pragma":"no-cache","content-type":"application/json; charset=utf-8","vary":"X-Origin, Referer, Origin,Accept-Encoding","server":"scaffolding on HTTPServer2","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"}
[2022-03-08T19:10:54.539Z] >>> HTTP REQUEST GET https://appengine.googleapis.com/v1/apps/eventos-staging-93d3a  
 
[2022-03-08T19:10:55.280Z] <<< HTTP RESPONSE 401 {"www-authenticate":"Bearer realm=\"https://accounts.google.com/\", error=\"invalid_token\"","vary":"X-Origin, Referer, Origin,Accept-Encoding","content-type":"application/json; charset=UTF-8","date":"Tue, 08 Mar 2022 19:10:55 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"}
[2022-03-08T19:10:55.281Z] <<< HTTP RESPONSE BODY {"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}}
[2022-03-08T19:10:55.282Z] error getting database typeHTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project. {"name":"FirebaseError","children":[],"context":{"body":{"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}},"response":{"statusCode":401,"body":{"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}},"headers":{"www-authenticate":"Bearer realm=\"https://accounts.google.com/\", error=\"invalid_token\"","vary":"X-Origin, Referer, Origin,Accept-Encoding","content-type":"application/json; charset=UTF-8","date":"Tue, 08 Mar 2022 19:10:55 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"},"request":{"uri":{"protocol":"https:","slashes":true,"auth":null,"host":"appengine.googleapis.com","port":443,"hostname":"appengine.googleapis.com","hash":null,"search":null,"query":null,"pathname":"/v1/apps/eventos-staging-93d3a","path":"/v1/apps/eventos-staging-93d3a","href":"https://appengine.googleapis.com/v1/apps/eventos-staging-93d3a"},"method":"GET"}}},"exit":1,"message":"HTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":401}
[2022-03-08T19:10:55.290Z] database_type: undefined

Error: It looks like you haven't used Cloud Firestore in this project before. Go to https://console.firebase.google.com/project/eventos-staging-93d3a/firestore to create your Cloud Firestore database.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Mar 8, 2022
@terasaka2k
Copy link

This seem to be a degration occurred from v10.2.0, from which some OAuth scopes are missing compared to login without --no-localhost option.

@sebastien-f
Copy link

I just had the same error, with the exact same context. I have the issue with 10.4.2.
Reverted to 10.1.5, it didn't work, so I logged out, logged in again and there it worked.

@PorcoRosso85
Copy link

I also did login firebase with option --no-localhost via firebase-cli v10.5.0.
In my case, it did not work when I logged out and in again.

@sebastien-f
Copy link

@PorcoRosso85 until this gets fixed I guess that you will have to go down to 10.1.5.

@ruhaifie
Copy link

hello, I'm in bandwagon when it comes to this problem: [firebase init firestore not work with existing project]
I'm using firebase CLI version 10.6.0

but somehow I manage to deal with it, here's my solution/timeline:

  1. I install using firebase login --no-localhost because encounter problems with firebase login
  2. encountered with errors: cannot install firestore but hosting part can.
  3. try to reset database, created again but still get error: cannot install firestore
  4. then I logout, then login using ONLY firebase login, not the firebase login --no-localhost
  5. bang! solved!

hope it helps~

@bkendall
Copy link
Contributor

We had to make an adjustment to the --no-localhost flow in the past week which should have addressed this issue. If you could give --no-localhost a try again, that'd be great. If there's more issues, please comment or open a new issue.

@trullock
Copy link

trullock commented Nov 8, 2022

I have this issue using latest firebase-tools as of today, --no-localhost doesn't help.

new local firebase project trying to connect to a new (an hour or so old) firebase project with Blaze billing enabled, web project created and firestore created/enabled.

debug logs:

[2022-11-08T23:06:27.479Z] <<< [apiv2][body] GET https://appengine.googleapis.com/v1/apps/XXXXX {"error":{"code":404,"message":"App does not exist.","status":"NOT_FOUND"}}
[2022-11-08T23:06:27.481Z] error getting database typeHTTP Error: 404, App does not exist. {"name":"FirebaseError","children":[],"context":{"body":{"error":{"code":404,"message":"App does not exist.","status":"NOT_FOUND"}},"response":{"statusCode":404}},"exit":1,"message":"HTTP Error: 404, App does not exist.","status":404}
[2022-11-08T23:06:27.483Z] database_type: undefined

(project id redacted)

@DerKO9
Copy link

DerKO9 commented Nov 10, 2022

I am also having this problem with version 11.16.0. I just made my project, initialized firestore database, and tried "firebase init"
Logging in with --no-localhost flag did not help

=== Firestore Setup
[2022-11-10T01:34:59.523Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/XXX/services/firestore.googleapis.com [none]
[2022-11-10T01:34:59.524Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/XXX/services/firestore.googleapis.com x-goog-quota-user=projects/XXX
[2022-11-10T01:34:59.841Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/XXX/services/firestore.googleapis.com 200
[2022-11-10T01:34:59.841Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/XXX/services/firestore.googleapis.com [omitted]
[2022-11-10T01:34:59.841Z] >>> [apiv2][query] GET https://appengine.googleapis.com/v1/apps/XXX [none]
[2022-11-10T01:35:00.243Z] <<< [apiv2][status] GET https://appengine.googleapis.com/v1/apps/XXX 404
[2022-11-10T01:35:00.243Z] <<< [apiv2][body] GET https://appengine.googleapis.com/v1/apps/XXX {"error":{"code":404,"message":"App does not exist.","status":"NOT_FOUND"}}
[2022-11-10T01:35:00.244Z] error getting database typeHTTP Error: 404, App does not exist. {"name":"FirebaseError","children":[],"context":{"body":{"error":{"code":404,"message":"App does not exist.","status":"NOT_FOUND"}},"response":{"statusCode":404}},"exit":1,"message":"HTTP Error: 404, App does not exist.","status":404}
[2022-11-10T01:35:00.244Z] database_type: undefined

Error: It looks like you haven't used Cloud Firestore in this project before. Go to https://console.firebase.google.com/project/XXX/firestore to create your Cloud Firestore database.

@lolz0r
Copy link

lolz0r commented Nov 10, 2022

I am having the same issue as well.

@trullock
Copy link

I waited ~12h to see if it was just some propagation issue but not joy.
Luckily I was able to delete the "existing" project and recreate it via the firebase cli.

@twilkinson573
Copy link

Also experiencing this issue

Recreating the project via the firebase cli didn't work unfortunately, still running into the same issue:
Error: It looks like you haven't used Cloud Firestore in this project before

Firestore setup/populated and Blaze billing enabled on everything

@superblockio
Copy link

Yep same issue. If I click the link it takes me to my database (which does exist, thank you very much.) If I use --debug, I get a 404 thing:

[2022-11-10T16:48:25.510Z] error getting database typeHTTP Error: 404, App does not exist. {"name":"FirebaseError","children":[],"context":{"body":{"error":{"code":404,"message":"App does not exist.","status":"NOT_FOUND"}},"response":{"statusCode":404}},"exit":1,"message":"HTTP Error: 404, App does not exist.","status":404}

@goofballLogic
Copy link

For me this was resolved by setting the "Default GCP resource location" under Project settings (which it forced me to set to the location of the Firestore database)

@RafaPatino01
Copy link

For me this was resolved by setting the "Default GCP resource location" under Project settings (which it forced me to set to the location of the Firestore database)

THIS WORKED!!

@trullock
Copy link

For me this was resolved by setting the "Default GCP resource location" under Project settings (which it forced me to set to the location of the Firestore database)

What exactly is this, and where?

Cheers

@sambshapiro
Copy link

sambshapiro commented Jan 22, 2023

FYI filed a bug report above as it seems many (including myself) continue to have this issue and get directed here likely via search. #5452

Seems to be a bug because intended behavior would be that this is handled gracefully. Options include:

  • Console prompting user to set the default GCP location when setting up the Firestore instance initially
  • CLI giving more descriptive error, that GCP default resource location needs to be set in the console
  • CLI automatically setting the default GCP resource location

@o2aya
Copy link

o2aya commented Jan 31, 2023

To solve the problem:
go to Project Overview >> Project Settings >> Set Default GCP resource location

@wstrother
Copy link

Setting the GCP location did NOT resolve the issue for me. Using the CLI tools version 11.22.0, I have tried logging in and out both with and without the --no-localhost flag, but it still insists I haven't set up a database when I most certainly have. Also I ensured the GCP location is set (nam5 (us-central))

Anyone have any other ideas?

@trullock
Copy link

trullock commented Feb 8, 2023

Setting the GCP location did NOT resolve the issue for me. Using the CLI tools version 11.22.0, I have tried logging in and out both with and without the --no-localhost flag, but it still insists I haven't set up a database when I most certainly have. Also I ensured the GCP location is set (nam5 (us-central))

Anyone have any other ideas?

Check you have the correct project selected in the cli. Can't remember the command off hand but it's obvious from the cli help

@wstrother
Copy link

I only have one Firebase project. I did check again just now to make sure, and to see if maybe the GCP change had finally propagated. Still no luck.

I am trying to push a hotfix to a project I deployed in early 2021 and haven't really touched since then, so maybe there is something else that has changed about the configuration I need to update?

Really appreciate your help!

@pavlovp
Copy link

pavlovp commented May 23, 2023

This is not fixed, I still get this - firebase version 11.4.2

@imajinate
Copy link

Yup, same here. The problem still exists.. My Default GCP resource location is filled in.. and tried the other mentioned solutions here above.. but no luck.

@mx5nabcd
Copy link

mx5nabcd commented Jun 10, 2023

If it doesn't work when you install a specific version, you can install latest version.
If you didn't install it "global", go into the project folder you created and use the 2 codes below
npm uninstall firebase
npm uninstall firebase-tools

Also, execute the following two codes regardless of whether they are global or not
npm uninstall -g firebase
npm uninstall -g firebase-tools

and
install latest version following two codes
npm install firebase (in the project folder)
npm install -g firebase-tools

before command "firebase init"
open your firebase console at the browser
and move bulid -> Firestore Database(in my case) -> click "make Database"(maybe)
and check GCP location
and command "firebase init"

I think setting firebase console before command firebase init is important

@Chinimala
Copy link

If it doesn't work when you install a specific version, you can install latest version. If you didn't install it "global", go into the project folder you created and use the 2 codes below npm uninstall firebase npm uninstall firebase-tools

Also, execute the following two codes regardless of whether they are global or not npm uninstall -g firebase npm uninstall -g firebase-tools

and install latest version following two codes npm install firebase (in the project folder) npm install -g firebase-tools

Setting GCP location + doing this worked, thank you.

@jimmy123A
Copy link

I think it's not possible to update the default GCP location anymore. I personally fixed it after upgrading the firebase-tools cli

@rangelak
Copy link

I second that. The current version is giving that there is no Firebase being used on a project that is running Firebase for the past month with GCP location set in Europe.

@bilkefpv
Copy link

The only way for me to finish the firebase init command was to pick "Don't set up a default project" and then run firebase use --add [project-id]

@fwadnjar
Copy link

Ok

@anhtuank7c
Copy link

I have the same problem, I have to use npx firebase init to solve the problem

@drewm1192
Copy link

How is this still a problem 2 years later? I am running into this now.

@morelazers
Copy link

I'm running into this issue, and the popular solution of modify the GCP location doesn't work for me, I receive the following error:

image

I also tried firebase use --add [projectid] but this didn't seem to do anything either.

I can tell that the CLI is connected to my default firestore instance, because I can retrieve the rules for it, but when I try to publish my firestore rules to another database, it appears to just ignore the non-default database.

@cricke
Copy link

cricke commented May 3, 2024

firebase logout firebase login

solves it for me... (for a while)

@joesscales
Copy link

I have the same problem, I have to use npx firebase init to solve the problem

I tried all the above and this is the only thing that worked for me.

@SoorajSNBlaze333
Copy link

Thanks @anhtuank7c. This is the only thing that worked for me after so many other options #4254 (comment)

@enricofoschi
Copy link

I kept having this issue, and it turns out that the only fix was to create a "(default)" name database.

@PeninPab
Copy link

I kept having this issue, and it turns out that the only fix was to create a "(default)" name database.

This was the only fix that worked because I couldn't modify the default GCP location. Thanks for posting this, I would have been stuck for days trying to figure this out.

@nimataplaw
Copy link

This is still an issue. Even when you create a default named database. Also cannot change the GCP location. This issue is several years old now.

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

No branches or pull requests