Figma exportAsync not returning and hanging

In below sample code,

Blockquote
export async function test()
{
const selection = Figma.currentPage.selection;
console.log("Selection length is ",selection.length)
if (selection.length > 0) {
const node = selection[0] as SceneNode;

    console.log("node is",node.name)
    **const imageData = await exportImage(node);** 
    console.log("POSTING....",imageData)
 figma.ui.postMessage({ type: 'imageData', imageData: imageData }); // Sending the image data back to the UI
}
else 
{
    console.warn('No layers selected.');
}

}

async function exportImage(node: SceneNode): Promise {
return new Promise((resolve) => {
const tempFrame = Figma.createFrame(); // Create a temporary frame
tempFrame.resize(node.width, node.height);
tempFrame.appendChild(node.clone()); // Clone and add the scene node to the temporary frame
const exportSettings: ExportSettingsImage = { format: ‘PNG’ };
tempFrame.exportAsync(exportSettings).then((imageBytes) => {
tempFrame.remove(); // Remove the temporary frame
resolve(imageBytes);
});
console.log(“OK”)
});

}

Blockquote
const imageData = await exportImage(node);
The call to exportImage is getting stuck. It is not returning…

But if I remove await there, it is returning but imageData is nothing. Could I ask what is wrong?

This issue might be related to the API call not completing successfully. Here are a few things you can try:

  1. Double-check the parameters you’re passing to the exportAsync function.
  2. Ensure that the file you’re trying to export is not too large or complex, which could cause the function to hang.
  3. Check your internet connection to ensure it’s stable.

I have this exact same issue with exportAsync, but I am using it to export SVG_STRING - the promise never errors or succeeds, so with async await it just halts.