Skip to main content
Question

figma.importStyleByKeyAsync throwing Error: Unable to create style


Sonny_Lazuardi_Hermawan

This plugin API was working before, after today’s update we got this error

Error: Unable to create style

Any advice?

This topic has been closed for replies.

24 replies

tank666
  • 4871 replies
  • March 1, 2023

Could you give an example of the code you use to import and create the style?
Also make sure the style with the key you are using exists in the library file.


Kyle_Wendt

I’ve run into this issue, too. @Sonny_Lazuardi_Hermawan were you able to get your issue resolved?


Kyle_Wendt

I’m having this issue, too. Here’s a code snippet.

async function toStyle(style) {

    let styles = {
        style_1: await figma.importStyleByKeyAsync(styleKey.style1),
    }

    ...

    inst.fillStyleId = styles.style_1.id;

}

Kyle_Wendt

Any help you can provide would be much appreciated! Thanks!


tank666
  • 4871 replies
  • March 2, 2023

Unfortunately, I can’t reproduce the error on my end. That is, my style is successfully imported and applied to the node.


Kyle_Wendt

Thanks for your attention @tank666 . I swear I had this working just last week…

I’ve done some diligence trying to simplify my attempt to just the essentials to try and get clarity.

I’m storing hard coded style keys in an object at the top level, followed by my async function ‘toStyle’ which takes an argument that’s passed to a switch/case.

Within the async function, I create an ‘itemStyle’ object where I collect the imported the styles, then loop through the selection, and attempt to apply the styles to the selections based on the switch/case argument.

I believe the error is occurring when the function is attempting to import the styles: ‘Uncaught (in promise) Error: Unable to create style’

const styleKey = {
  style_1: [key],
  [...]
}

async function toStyle(arg) {

  let itemStyle = {
    itemStyle_1: await figma.importStyleByKeyAsync(styleKey.style_1),
    [...]
  }
  
  for(const item in figma.currentPage.selection) {
    switch(arg) {
      case 'applyStyle_1': 
        figma.currentPage.selection[item].fillStyleId = itemStyle.itemStyle_1.id; 
        break;
      [...]
    }
  }
}

Interestingly, as I’m opening a fresh Figma file for testing and placing my components to test on, I’m getting some messages in the console that read:

[symbol] failed to repair styles

Thanks again for your attention.


I’m facing same issue with this pluginAPI

 await figma.importStyleByKeyAsync(style.key)

After inspecting, the figma API respond with no error and successfully fetch the style, but the style key returned is different with the one requested. I assume the error happen on the client side.

Most of the styles can load correctly withawait figma.importStyleByKeyAsync(style.key), but only 50 of them in our library getting this error. Those impacted styles are created in 2021.


James_Yang
Figmate
  • Figmate
  • 82 replies
  • March 4, 2023

@Hao_Zhang So importStyleByKeyAsync throws an error for you for some styles, but the network request is succeeding? If you’re hard-coding the style keys some where, we recommend that you migrate to use the new keys returned by the network request.

The background here is that we’ve been making backend changes to the style key contents and so plugins using hard-coded keys obtained a while ago may end up using outdated keys.

@Sonny_Lazuardi_Hermawan Are you seeing the same behavior with the error being thrown but the network request to fetch the style succeeding? If so, I’d recommend using the info above to switch to using the new key from the network response.


thomas_TikTok-Design-UX-APAC

hi, i have the same issue


thomas_TikTok-Design-UX-APAC

i use restful api to get all styles from one lib file.Then i use figma.importStyleByKeyAsync to import all style key. On some file it looks fine.But in some files, this error occurs


thomas_TikTok-Design-UX-APAC

request return the same key that i used to importStyleByKeyAsync


Yeonhee_Lee

I see the same error when I run the plugin against a file I have the editor’s access to. It doesn’t happen if I copy the same file and run the same plugin against as an owner.
Does this bug have anything to do with the authority?


I’m using the latest style key return by figma API. Not sure if the backend changes you mentioned affected those style created a few years ago.

The network request was success. I believe it’s the Figma client that throws the error

I’m using https://api.figma.com/v1/files/${file_id} to fetch all the style keys. My guess here it might related to this api returning outdated style keys.


thomas_TikTok-Design-UX-APAC

i found that style key get from rest api return is different from getLocalPaintsStyles
that’s why this error happen


thomas_TikTok-Design-UX-APAC

yes, if you run getLocalPaintsStyles in lib file,you will find that key is different from https://api.figma.com/v1/files/${file_id}


Alexander_Rodin

Hi, any solution for this one? Also ran into the same error


Daniel_Buitrago_Jara

Hi, is there a solution for this issue?

I already confirmed that the style ids where updated (they didn’t change in my case) and it keeps throwing the same error.


James_Yang
Figmate
  • Figmate
  • 82 replies
  • March 14, 2023

Hi all, we plan to roll out a fix for this “Unable to create style” error by the end of day Wednesday March 15. This error primarily comes up for older styles that have been moved to another file.


Alexander_Rodin

Still getting the same error. Maybe there is something I need to do with the style in the lib for the fix to work?


MaxBazarov
  • Active Member
  • 21 replies
  • March 17, 2023

I also can’t load team style by ID.


MaxBazarov
  • Active Member
  • 21 replies
  • March 24, 2023

Today is March 24, but it still doesn’t work


MaxBazarov
  • Active Member
  • 21 replies
  • April 2, 2023

Any news from Figma?


James_Yang
Figmate
  • Figmate
  • 82 replies
  • April 2, 2023

“Failed to import style by key” is a different error from “Unable to create style”. Also, the style id is different from the key – importStyleByKeyAsync only accepts the latter.

If you are anyone is still getting the “Unable to create style” error for a style key you know to exist, feel free to DM me the relevant details (the style key and console output) and we can investigate.


Bryan_Wong

Hi James, I am running into the same issue. I believe it is a result of this:

This error primarily comes up for older styles that have been moved to another file.

How do I fix this?


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings