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 with /var/ when using style-dictionary in a Lambda function #1104

Closed gaulatti closed 5 months ago

gaulatti commented 7 months ago

I'm trying to create a Lambda with custom formatters, however as soon as trying to register the formatters I get the following error:

{
    "errorType": "Error",
    "errorMessage": "ENOENT: no such file or directory, open '/var/task/templates/css/fonts.css.template'",
    "code": "ENOENT",
    "errno": -2,
    "syscall": "open",
    "path": "/var/task/templates/css/fonts.css.template",
    "stack": [
        "Error: ENOENT: no such file or directory, open '/var/task/templates/css/fonts.css.template'",
        "    at Object.openSync (node:fs:596:3)",
        "    at Object.readFileSync (node:fs:464:35)",
        "    at node_modules/style-dictionary/lib/common/formats.js (/var/task/index.js:7853:12)",
        "    at __require (/var/task/index.js:12:50)",
        "    at node_modules/style-dictionary/index.js (/var/task/index.js:20008:15)",
        "    at __require (/var/task/index.js:12:50)",
        "    at Object.<anonymous> (/var/task/index.js:20777:39)",
        "    at Module._compile (node:internal/modules/cjs/loader:1356:14)",
        "    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)",
        "    at Module.load (node:internal/modules/cjs/loader:1197:32)"
    ]
}

Is this happening by default on iniitalization? When running locally or in CodeBuild this error does not happen.

jorenbroekema commented 5 months ago

The line of code creating the error is fs.readFileSync(__dirname + '/templates/css/fonts.css.template').

I suspect that maybe you're running it on Windows where paths have backwards slashes \ instead of forward /, or that __dirname is not properly resolved in the environment you're running this.

Either way, in v4 we're not using these kinds of paths to .template files anymore, but rather we're just importing the templates as regular ES Modules, that should make this problem disappear. We're releasing v4 in June btw