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.
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’
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.
@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.
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
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.
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.
“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.
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.