amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.87k stars 543 forks source link

Reference doesn't exist: X tries to reference Y, which is not defined #903

Open LoadJulz opened 1 year ago

LoadJulz commented 1 year ago

I have a problem with resolving references in my figma token file. Our figma token file is organized as follows: [Light/Dark/Global]/Fontfamilies. When I define my fonts in Figma and use the fontFamily of the global theme, a relative reference is created that does not include the source (global) of the reference, i.e. the reference "{fontFamilies.body}" should be "{global.fontFamilies.body}" for it to work. Here is an excerpt from my token file.

"global": { "fontFamilies": { "heading": { "value": "Montserrat", "type": "fontFamilies" }, "body": { "value": "Montserrat", "type": "fontFamilies" } }, "paragraph": { "xs": { "value": { "fontFamily": "{fontFamilies.body}", "lineHeight": "{lineHeights.paragraph}", "fontWeight": "{fontWeights.regular}", "fontSize": "{fontSizes.xs}", "letterSpacing": "{letterSpacings.default}" }, "type": "typography" } } }

Does anybody has an workaround to still be able to convert this token file into a style_directory? Renaming all the references is no possible solution because the token file has around 1500 lines.

vishrayne commented 1 year ago

Not sure if this would help you... :pray:

How are you exporting your tokens file? If you're using Tokens studio for Figma, while exporting you could see a setting as Include parent key which is turned on by default. Disable that before exporting the file.

image

sebazelonka commented 1 year ago

Hello, I have the same issue and basically, I don't want to loose the parent key, because I'm using it to filtering tokens.

Is there a better way to solve this issue?

mavo-pfizer commented 1 year ago

+1

henriksonnergard commented 1 year ago

Just ran into this as well while testing a tool chain of Tokens Studio and Style Dictionary. We use global tokens as a base layer that should not be used directly but are referenced by alias tokens.