Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The font could not be loaded #93

Open
tomasdev opened this issue Jan 27, 2022 · 1 comment
Open

The font could not be loaded #93

tomasdev opened this issue Jan 27, 2022 · 1 comment

Comments

@tomasdev
Copy link

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 figma/community#2 ?

@sharan3102
Copy link

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants