I’m trying to use the firebase admin sdk in one of my netlify functions to update a firebase firestore database. However, when I run the function, it always returns an error.
Here’s the code for my function:
export async function handler(event, context) {
const id = Math.floor(Math.random() * 10000000 + 1);
await admin
.firestore()
.collection("hello")
.doc("world")
.set({ hi: true, id });
return {
statusCode: 200,
body: `done with id ${id}`,
};
}
Whenever I run it (by opening https://montavistamun.netlify.app/.netlify/functions/test in the browser),
I get an error.
The full functions folder is here.
And the full logs are here:
3:23:17 AM: 2020-08-12T10:23:17.452Z dfe3d147-ec1a-4193-b527-3f7e31595ffb ERROR Invoke Error {"errorType":"Error","errorMessage":"error reading first path in the walk /protos\nError: ENOENT: no such file or directory, lstat '/protos'","stack":["Error: error reading first path in the walk /protos","Error: ENOENT: no such file or directory, lstat '/protos'"," at EventEmitter.<anonymous> (/var/task/src/built-netlify-functions/test.js:1135:4027)"," at Object.onceWrapper (events.js:422:26)"," at EventEmitter.emit (events.js:315:20)"," at o (/var/task/src/built-netlify-functions/test.js:1135:2743)"," at O (/var/task/src/built-netlify-functions/test.js:1135:2841)"," at a (/var/task/src/built-netlify-functions/test.js:1135:4093)"," at Function.a.sync (/var/task/src/built-netlify-functions/test.js:1135:4450)"," at Object.<anonymous> (/var/task/src/built-netlify-functions/test.js:375:10125)"," at Object.<anonymous> (/var/task/src/built-netlify-functions/test.js:375:12959)"," at r (/var/task/src/built-netlify-functions/test.js:1:158)"]}
3:23:17 AM: Duration: 276.86 ms Memory Usage: 91 MB Init Duration: 250.77 ms
3:23:36 AM: 2020-08-12T10:23:36.724Z aabe6a0a-8433-4070-bc2e-c39d3e9b4734 ERROR Invoke Error {"errorType":"TypeError","errorMessage":"t is not a constructor","stack":["TypeError: t is not a constructor"," at /var/task/src/built-netlify-functions/test.js:1135:584"," at new e (/var/task/src/built-netlify-functions/test.js:1135:593)"," at /var/task/src/built-netlify-functions/test.js:856:4457"," at e.ensureService_ (/var/task/src/built-netlify-functions/test.js:856:5922)"," at e.firestore (/var/task/src/built-netlify-functions/test.js:856:4411)"," at e.t (/var/task/src/built-netlify-functions/test.js:840:4869)"," at Runtime.i [as handler] (/var/task/src/built-netlify-functions/test.js:1341:7917)"," at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}
3:23:36 AM: Duration: 27.21 ms Memory Usage: 92 MB
3:23:47 AM: 2020-08-12T10:23:47.753Z 51e2c2e9-ceda-42b7-8b09-391785978425 ERROR Invoke Error {"errorType":"TypeError","errorMessage":"t is not a constructor","stack":["TypeError: t is not a constructor"," at /var/task/src/built-netlify-functions/test.js:1135:584"," at new e (/var/task/src/built-netlify-functions/test.js:1135:593)"," at /var/task/src/built-netlify-functions/test.js:856:4457"," at e.ensureService_ (/var/task/src/built-netlify-functions/test.js:856:5922)"," at e.firestore (/var/task/src/built-netlify-functions/test.js:856:4411)"," at e.t (/var/task/src/built-netlify-functions/test.js:840:4869)"," at Runtime.i [as handler] (/var/task/src/built-netlify-functions/test.js:1341:7917)"," at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}
3:23:47 AM: Duration: 6.29 ms Memory Usage: 93 MB
3:29:44 AM: 2020-08-12T10:29:44.570Z 4c4a1cf9-c949-4d1b-8637-63063da8cef3 ERROR Invoke Error {"errorType":"TypeError","errorMessage":"t is not a constructor","stack":["TypeError: t is not a constructor"," at /var/task/src/built-netlify-functions/test.js:1135:584"," at new e (/var/task/src/built-netlify-functions/test.js:1135:593)"," at /var/task/src/built-netlify-functions/test.js:856:4457"," at e.ensureService_ (/var/task/src/built-netlify-functions/test.js:856:5922)"," at e.firestore (/var/task/src/built-netlify-functions/test.js:856:4411)"," at e.t (/var/task/src/built-netlify-functions/test.js:840:4869)"," at Runtime.i [as handler] (/var/task/src/built-netlify-functions/test.js:1341:7917)"," at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}
3:29:44 AM: Duration: 2.02 ms Memory Usage: 93 MB
I found a somewhat related issue here, but the solution from that issue doesn’t work, and my function builds properly.