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

styleDictionary.buildAllPlatforms is not a function #994

Closed fwielstra closed 11 months ago

fwielstra commented 1 year ago

I'm trying to get style dictionary to work, following the instructions, but when running build or trying to redo the initial setup into my project I'm getting the following error:

Copying starter files...

Source style dictionary starter files created!

Running `style-dictionary build` for the first time to generate build artifacts.

/Users/freek/workspace/essent/mobile-apps-v2/node_modules/browser-style-dictionary/bin/style-dictionary:91
    styleDictionary.buildAllPlatforms();
                    ^

TypeError: styleDictionary.buildAllPlatforms is not a function
    at styleDictionaryBuild (<myproject>/node_modules/browser-style-dictionary/bin/style-dictionary:91:21)
    at Command.<anonymous> (<myproject>/node_modules/browser-style-dictionary/bin/style-dictionary:70:5)
    at Command.listener [as _actionHandler] (<myproject>/node_modules/browser-style-dictionary/node_modules/commander/lib/command.js:488:17)
    at <myproject>/node_modules/browser-style-dictionary/node_modules/commander/lib/command.js:1227:65
    at Command._chainOrCall (<myproject>/node_modules/browser-style-dictionary/node_modules/commander/lib/command.js:1144:12)
    at Command._parseCommand (<myproject>/node_modules/browser-style-dictionary/node_modules/commander/lib/command.js:1227:27)
    at Command._dispatchSubcommand (<myproject>/node_modules/browser-style-dictionary/node_modules/commander/lib/command.js:1050:25)
    at Command._parseCommand (<myproject>/node_modules/browser-style-dictionary/node_modules/commander/lib/command.js:1193:19)
    at Command.parse (<myproject>/node_modules/browser-style-dictionary/node_modules/commander/lib/command.js:897:10)
    at Object.<anonymous> (<myproject>/node_modules/browser-style-dictionary/bin/style-dictionary:111:9)

I can't proceed with anything because of this. Any idea how to resolve this?

olliequ commented 1 year ago

how'd you solve?

gaulatti commented 1 year ago

bump

brett-sprad commented 1 year ago

so I solved this by running npm i style-dictionary -g so that it is a global install, not a local install. For some reason if you install style-dictionary locally only, you can't use it in a script (package.json)

gaulatti commented 1 year ago

Actually, I think the problem here is that the error message is misleading. If you don't do extend correctly the entire object won't work and you won't have buildAllPlatforms available. After rewriting the whole extend usage, it worked correctly without having to do a global install.

jorenbroekema commented 11 months ago

if you do npm ls browser-style-dictionary you may find that browser-style-dictionary is installed as a dependency of @tokens-studio/sd-transforms. What actually happens is that this browser-patch of style-dictionary replaces the "real" style-dictionary binary file in the node_modules/.bin folder, so what you are actually running is browser-style-dictionary, even if you also install style-dictionary as a dependency in your project.

This wouldn't be a big problem normally, but there is a regression in this browser-patch that stopped supporting CommonJS style-dictionary config files (module.exports = { ...your SD config... }), so then you get this error.

I have fixed @tokens-studio/sd-transforms this week to no longer rely on this broken browser-patch, so if you delete your node_modules and install the latest (0.11.8 as of writing this), this issue should be fixed.

Either way, the issue is related to @tokens-studio/sd-transforms and browser-style-dictionary, see https://github.com/tokens-studio/sd-transforms/issues/197. Therefore, closing this one