I have an existing plugin that I have created that has the functionality to render text. I have already loaded fonts before rendering the text on a shape. However, I got this error displayed
Cannot write to node with unloaded font \"Inter Regular\". Please call figma.loadFontAsync({ family: \"Inter\", style: \"Regular\" }) and await the returned promise first.
/**
* load fonts that is selected
* @param {FontName} fontStyle
* @returns {Promise<void>}
*/
const loadFont = async (fontStyle: FontName): Promise<void> => {
await figma.loadFontAsync(fontStyle);
};
/**
* Renders text into their corresponding text box
* @param {string} text - text to render.
* @param {number} width
* @param {number} height
* @param {number} x
* @param {number} y
* @returns {Promise<TextNode>}
*/
const renderText = async (
text: string,
width: number,
height: number,
x: number,
y: number
): Promise<TextNode> => {
await loadFont({ family: "Roboto", style: "Regular" });
const textBox = figma.createText();
textBox.resize(width, height);
textBox.textAutoResize = "HEIGHT";
textBox.insertCharacters(0, text);
textBox.fontSize = textSize;
textBox.textAlignHorizontal = "LEFT";
textBox.textAlignVertical = "TOP";
textBox.x = x;
textBox.y = y;
return textBox;
};
Does anyone face the same issue as I did?