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

Firestore Repeatedly Returning Error: 5 NOT_FOUND #2563

Closed
sr5434 opened this issue May 16, 2024 · 12 comments
Closed

Firestore Repeatedly Returning Error: 5 NOT_FOUND #2563

sr5434 opened this issue May 16, 2024 · 12 comments
Assignees

Comments

@sr5434
Copy link

sr5434 commented May 16, 2024

[READ] Step 1: Are you in the right place?

Cloud Firestore support is provided by the @google-cloud/firestore library. Therefore the easiest and most efficient way to get Firestore issues resolved is by directly reporting them at the nodejs-firestore GitHub repo.

If you still think the problem is related to the code in this repository, then read on.

  • For issues or feature requests related to the code in this repository
    file a Github issue.
  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Ubuntu
  • Firebase SDK version: 13.9.0
  • Firebase Product: Firestore
  • Node.js version: v20.12.1
  • NPM version: 10.5.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

When I call the API Route, instead of creating a new user in Firestore, I get a vague "Error: 5 NOT_FOUND" error message with no additional details. I have used this code before in other projects and can confirm that it used to work.

Relevant Code:

The following is a NextJS API Route I used.

import { NextResponse, Response } from 'next/server'

import { getFirestore } from "firebase-admin/firestore";
import * as admin from 'firebase-admin'

const serviceAccount = require('../../../service_account.json');
if (admin.apps.length === 0) {
  admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: 'https://database.firebaseio.com'
  });
}
const db = getFirestore();

export async function POST(req){
  const {userId} = getAuth(req);
  const usersDb = db.collection('users');
  await usersDb.doc("example-user-id").set({
    customers: []
  });
  return NextResponse.json({ result: "Success" });
}
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@lahirumaramba
Copy link
Member

Did you enable Firestore from the Firebase console? I have seen this error before when Firestore is not properly set up from the console.

@sr5434
Copy link
Author

sr5434 commented May 21, 2024

When I create a firebase app instead of using a service account it works sometimes

@caravelle-inc
Copy link

@lahirumaramba @sr5434
I am also experiencing this issue.

I have two projects, one for development and one for production, and I am initializing Firestore using a service account. The development project does not have this issue. However, when I set up the production project yesterday, the problem occurred. (BTW, the same problem occurs in the production project, even in the emulator environment.) We have confirmed that the correct service account for the project is being loaded.

Here are the details:

// package.json
{
 "engines": {
    "node": "18"
  },
  "dependencies": {
    "firebase-admin": "^11.11.1",
    "firebase-functions": "^5.0.1"
  }
}
// firebaseConfig.js
const admin = require("firebase-admin");
require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` });
const serviceAccount = require(process.env.SERVICE_ACCOUNT_KEY);

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
});
console.log(serviceAccount);

const db = admin.firestore();
module.exports = { db };

I found the same information and wanted to share it for your reference:
https://ja.stackoverflow.com/questions/99288/node-js-%e3%81%a7-gcp-%e3%81%ae-cloud-functions-%e3%81%8b%e3%82%89-firestore-%e3%81% ae%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e5%8f%96%e5%be%97%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95%e3%81%8c%e5%88%86%e3%81%8b%e3%82%89%e 3%81%aa%e3%81%84

Thank you for reading!

@caravelle-inc
Copy link

Additionally, I conducted further investigations and would like to report the findings for your reference.

Firstly, regarding the Firestore activation, I was able to manually add data from the console screen, so I believe Firestore has been successfully activated.

Next, I tried the recommended method from the official documentation as follows, but the error situation remains the same.

const { getFirestore } = require("firebase-admin/firestore");
const { initializeApp } = require("firebase-admin/app");

const app = initializeApp();
console.log("initializeApp", app);

const db = getFirestore();
console.log("getFirestore", db);

module.exports = { db };

@lahirumaramba
Copy link
Member

I have two projects, one for development and one for production, and I am initializing Firestore using a service account. The development project does not have this issue. However, when I set up the production project yesterday, the problem occurred.

Did you follow the same steps to generate both service accounts and were they generated on the Firebase Console?

@caravelle-inc
Copy link

Yes, I believe I followed the same steps. I created both of these projects at the same time about a month ago. I issued the service account key for the production project a few days ago.

@ehsannas ehsannas assigned dconeybe and unassigned ehsannas May 29, 2024
@dconeybe
Copy link

I'll take a look at this tomorrow. For now, do you have some log output showing the entire stack trace and error message that you could post?

@sr5434
Copy link
Author

sr5434 commented May 30, 2024

I was able to get the code working when I used the Firebase NPM package on the backend and created a web app in the firebase console.

@dconeybe
Copy link

Is your problem solved?

@sr5434
Copy link
Author

sr5434 commented May 31, 2024

Yes

@sr5434 sr5434 closed this as completed May 31, 2024
@caravelle-inc
Copy link

The production project required a specified database ID. The issue is resolved. Thank you!

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

6 participants