Hi there,
I was migrating our functions to typescript (when they were pure JS, they’d run just fine) so I’m running into this weird issue with (I think) the firebase admin SDK.
The functions build just fine, but upon calling them, it throws this magnificent thing:
Error: ENOENT: no such file or directory, open 'protos.json'
Object.openSync (fs.js:476:3)
Object.readFileSync (fs.js:377:35)
fetch (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:84789:28)
Root.load (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:84818:9)
Root.loadSync (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:84828:17)
Object.loadProtosWithOptionsSync (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:87952:29)
Object.loadSync (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:88100:31)
GrpcClient.loadFromProto (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:88924:44)
GrpcClient.loadProto (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:88942:19)
new FirestoreClient (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:128150:36)
sed by: Error
Firestore.getAll (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:128804:21)
DocumentReference.get (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:111311:30)
saveToFirebase (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:131852:23)
Object.handler (D:\Github\<project-folder>\.netlify\functions-serve\subscribeToNewsletter\src\index.js:131908:31)
processTicksAndRejections (internal/process/task_queues.js:93:5)
Now, I’ve tried/looked through:
- ENOENT: no such file or directory, open 'protos.json' · Issue #489 · googleapis/nodejs-speech · GitHub
- https://answers.netlify.com/t/project-of-next-js-with-getserversideprops-got-an-error-when-rendering/30009
- Firebase Error in Next.js Netlify function
But unfortunately, none helped my situation.
I have also seen this, but since Netlify uses esbuild I don’t know how to set that (__dirname: true) (or equivalent) option.
Code Sample (functions/firebase/firebase.ts) saveToFirebase gets called from the functions/subscribeToNewsletter/index.ts:
import * as firebase from "firebase-admin";
import * as rawServiceAccount from "./[...].json";
import { FirebaseOps } from "../constants";
import { SubscribeFormData, UnsubscribeFormData } from "../interfaces";
import { Logger } from "../logger";
const serviceAccount = {
type: rawServiceAccount.type,
projectId: rawServiceAccount.project_id,
privateKeyId: rawServiceAccount.private_key_id,
privateKey: rawServiceAccount.private_key,
clientEmail: rawServiceAccount.client_email,
clientId: rawServiceAccount.client_id,
authUri: rawServiceAccount.auth_uri,
tokenUri: rawServiceAccount.token_uri,
authProviderX509CertUrl: rawServiceAccount.auth_provider_x509_cert_url,
clientC509CertUrl: rawServiceAccount.client_x509_cert_url
}
const saveToFirebase = async (
formData: SubscribeFormData | UnsubscribeFormData,
operation: FirebaseOps
): Promise<string> => {
try {
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
});
} catch (e) {
Logger.warn(e);
}
[...]
};
export { saveToFirebase }
Website: https://buyprisma.netlify.app/. Currently the JS files are deployed, since I couldn’t get the TS Scripts to work.