Skip to content
Advertisement

Axios in a firebase function returning pending promise even inside two async/await blocks

I have an async/await problems (I know, I know) that makes no sense to me. I’m declaring both functions (child and HOF) as async, and awaiting the returned results before trying to console log them. Surprise surprise, I get pending. The function hangs for 60s and times out (so it seems even my runWith timeout method isn’t working. Also tried logging a simple “here” right before declaring const fetchData, but also that didn’t log. And yet console logging after actually calling the fn does…

JavaScript

I wanted to use fetch but apparently node-fetch doesn’t work well with firebase.

I will try to provide a list of the many SO posts and articles I’ve read about async/await. I’ve done the research and tried all of their implementations, but still can’t resolve it.

Stack overflow formatting is not working, so:

Axios returning pending promise async/await return Promise { <pending> } Why is my asynchronous function returning Promise { <pending> } instead of a value? Async/await return Promise<pending> https://github.com/Keyang/node-csvtojson/issues/278 https://www.reddit.com/r/Firebase/comments/h90s0u/call_external_api_from_cloud_function/

Advertisement

Answer

You are using too many await in your code.
If you want to use await on the fetchData function you should return a Promise and handle it outside.

Try to change your code like this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement