You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
Trying to include fonts in my style dictionary, I encounter an error when encoding fonts file into base64.
Been trying with fonts from google font and even fonts provided in your examples/advanced/assets-base64-embed repo, always the same error:
node:buffer:1256
throw lazyDOMException('Invalid character', 'InvalidCharacterError');
^
DOMException [InvalidCharacterError]: Invalid character
at btoa (node:buffer:1256:13)
at convertToBase64 (file:///my_local_path/Source/node_modules/style-dictionary/lib/utils/convertToBase64.js:31:10)
at Object.transform (file:///my_local_path/Source/node_modules/style-dictionary/lib/common/transforms.js:1395:14)
at transformToken (file:///C:/my_local_path/Source/node_modules/style-dictionary/lib/transform/token.js:67:52)
at async transformObject (file:///my_local_path/Source/node_modules/style-dictionary/lib/transform/object.js:102:32)
at async transformObject (file:///my_local_path/Source/node_modules/style-dictionary/lib/transform/object.js:125:30)
at async transformObject (file:///my_local_path/Source/node_modules/style-dictionary/lib/transform/object.js:125:30)
at async transformObject (file:///my_local_path/Source/node_modules/style-dictionary/lib/transform/object.js:125:30)
at async StyleDictionary._exportPlatform (file:///my_local_path/Source/node_modules/style-dictionary/lib/StyleDictionary.js:512:27)
at async StyleDictionary.getPlatformTokens (file:///my_local_path/Source/node_modules/style-dictionary/lib/StyleDictionary.js:411:26)
Been trying to open files with Notepad++ and converting them to UTF8 with no difference in the output.
If this can help, I'm running on Windows and using npm run build locally. The CLI is not globally installed as I prefer keeping it in the project.
Thanks for your help
The text was updated successfully, but these errors were encountered:
I think we need to use a Node/Browser compatible way to read a font file, convert it to base64 properly:
constbody=fs.readFileSync(filePath);consttoBase64=buffer=>{if(typeofwindow!=='object'){// In Node we have Buffer and it's easyreturnBuffer.from(buffer).toString('base64');}else{// In browser we can use FileReader & Blobconstreader=newFileReader();constblob=newBlob([body]);reader.readAsDataURL(blob);returnnewPromise(resolve=>{reader.onloadend=()=>{resolve(reader.result);};});}};constb64String=toBase64(body);
Thx @jorenbroekema. If it might help others, to be able to move forward, I took the pass of copying my files as assets and let my consuming app to base64encode. Working fine for me right now, and tbh, feeling a bit better with this solution.
Hi!
Trying to include fonts in my style dictionary, I encounter an error when encoding fonts file into base64.
Been trying with fonts from google font and even fonts provided in your
examples/advanced/assets-base64-embed
repo, always the same error:Been trying to open files with Notepad++ and converting them to UTF8 with no difference in the output.
If this can help, I'm running on Windows and using
npm run build
locally. The CLI is not globally installed as I prefer keeping it in the project.Thanks for your help
The text was updated successfully, but these errors were encountered: