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

Error building using js config #1289

Closed magomarlon closed 2 months ago

magomarlon commented 2 months ago

Hi folks.

I'm getting this error by using a js config:

node_modules/style-dictionary/lib/StyleDictionary.js:235
      ...options.log,
                 ^

TypeError: Cannot read properties of undefined (reading 'log')
    at StyleDictionary.extend 

This is my config (styledictionary.js):

import StyleDictionary from "style-dictionary"

const sd = new StyleDictionary("config.json")
await sd.buildAllPlatforms()

This is styledictionary.json:

{
  "source": ["src/tokens/base/**/*.json"],
  "platforms": {
    "css": {
      "transformGroup": "css",
      "buildPath": "src/tokens/build/css/",
      "files": [
        {
          "destination": "tokens.css",
          "format": "css/variables"
        }
      ]
    },
    "js": {
      "transformGroup": "js",
      "buildPath": "src/tokens/build/js/",
      "files": [
        {
          "destination": "tokens.ts",
          "format": "javascript/es6"
        }
      ]
    }
  }
}

I'm running with this command: npx style-dictionary build --config styledictionary.js If I use directly use the config.json as a default config it works perfectly, so I guess the config.json is Ok

And my package.json: "style-dictionary": "^4.0.1" Node version used: 20.9.0

jorenbroekema commented 2 months ago

You're combining running Style Dictionary using the CLI build command with running it through the NodeJS API.

Try either running this:

npx style-dictionary build --config config.json

Or running:

node styledictionary.js