The font could not be loaded
The following snippet logs a warning unhandled promise rejection: Throw: The font "My Font Regular" could not be loaded
figma.listAvailableFontsAsync().then(fonts => {
for (const font of fonts) {
if (font.fontName.family === 'My Font' && font.fontName.style === 'Regular') {
figma.loadFontAsync(font.fontName).then(() => {
console.log('loaded fine');
});
}
}
});
I purposefully chose not to have an error handler, since this code shouldn't actually fail.
I'm developing a variable font and I seem unable to load it via a plugin. Is this just a consequence of https://github.com/figma/community/issues/2 ?
Hey Tomas, I think this error is happening because the code couldn't access the font mentioned. Try checking the font path and verify the permissions if there are any. Make sure that the font is in (.otf or .ttf) format as Figma only supports these two formats. I think this would help you.
The updated code with error handling block 👇🏻
figma.listAvailableFontsAsync().then(fonts => {
for (const font of fonts) {
if (font.fontName.family === 'My Font' && font.fontName.style === 'Regular') {
figma.loadFontAsync(font.fontName)
.then(() => {
console.log('Font loaded successfully');
})
.catch(error => {
console.error('Failed to load font:', error);
});
}
}
}).catch(error => {
console.error('Failed to retrieve available fonts:', error);
});