4

I was learning firebase to integrate with my react web app. I was trying to write functions for GET and POST requests and running them on postman using endpoints i get in my terminal in vscode. Now my code works perfectly with firebase deploy but gives me errors with i try using firebase serve. also i cannot just use these commands simply , i have to run them using sudo and then enter my password and only then i'm able to run them. below is the error list

The Cloud Firestore emulator is not running, so calls to Firestore will affect production.

⚠ External network resource requested! - URL: "http://169.254.169.254/computeMetadata/v1/instance" - Be careful, this may be a production service.

⚠ External network resource requested! - URL: "http://metadata.google.internal./computeMetadata/v1/instance" - Be careful, this may be a production service.

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.

 at GoogleAuth.getApplicationDefaultAsync (/home/nikunj/socialape-functions/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:160:19)

 at processTicksAndRejections (internal/process/task_queues.js:97:5)

 at async GoogleAuth.getClient (/home/nikunj/socialape-functions/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:502:17)

 at async GrpcClient._getCredentials (/home/nikunj/socialape-functions/functions/node_modules/google-gax/build/src/grpc.js:92:24)

 at async GrpcClient.createStub (/home/nikunj/socialape-functions/functions/node_modules/google-gax/build/src/grpc.js:213:23)

Caused by: Error

 at WriteBatch.commit (/home/nikunj/socialape-functions/functions/node_modules/@google-cloud/firestore/build/src/write-batch.js:415:23)

 at DocumentReference.create (/home/nikunj/socialape-functions/functions/node_modules/@google-cloud/firestore/build/src/reference.js:283:14)
 at CollectionReference.add (/home/nikunj/socialape-functions/functions/node_modules/@google-cloud/firestore/build/src/reference.js:2011:28)
 at /home/nikunj/socialape-functions/functions/index.js:32:10
 at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:559:20
 at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:534:19
 at Generator.next (<anonymous>)
 at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:8:71
 at new Promise (<anonymous>)
 at __awaiter (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:4:12)

i functions: Finished "createScream" in ~1s

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Nik
  • 187
  • 3
  • 17

3 Answers3

5

i actually solved this by giving in the credentials using service account in firebase project setting. i changed my intialise app to

    var serviceAccount = require("path/to/serviceAccountKey.json");

    admin.initializeApp({
     credential: admin.credential.cert(serviceAccount),
     databaseURL: "https://socialape-6925b.firebaseio.com"
     });```
Nik
  • 187
  • 3
  • 17
3

For me the missing step was that I had not initialized the firestore emulator using

firebase init emulators
AyKarsi
  • 9,435
  • 10
  • 54
  • 92
  • I still don't understand how this stuff works all i do is check for solutions online and try and understand what changes could help me out :) – Nik Aug 22 '20 at 17:56
-1

Yes I also got the same error but I solve this.

First , make sure you have .firebaserc file in your project folder then initialize the admin using:-

admin.initializeApp();
user14678216
  • 2,886
  • 2
  • 16
  • 37
ROHIT
  • 9
  • 4