Hi,
I am trying to import a JSON file to my code.ts file but it does not work. I am trying to load the JSON this way:
const data = require("C:/Users/Administrateur/Downloads/example_1.json");
Where example_1.json looks like:
{
“fruit”: “Apple”,
“size”: “Large”,
“color”: “Red”
}
But I get the following error in the console of Figma:
ReferenceError: exports is not defined
at Proxy.eval (/file/YHp4UvwlZfU65BKOOnMnDV/PLUGIN_73_SOURCE:40)
at Object.eval (eval at createScopedEvaluatorFactory (blob:https://www.figma.com/f61f62e1-6843-4c14-9beb-bc45dca43550:1), :8:16)
at blob:https://www.figma.com/f61f62e1-6843-4c14-9beb-bc45dca43550:9
at blob:https://www.figma.com/f61f62e1-6843-4c14-9beb-bc45dca43550:9
at realmEvaluate (blob:https://www.figma.com/f61f62e1-6843-4c14-9beb-bc45dca43550:9)
at eval (eval at createCallAndWrapError (blob:https://www.figma.com/f61f62e1-6843-4c14-9beb-bc45dca43550:1), :1:615)
at Realm.evaluate (blob:https://www.figma.com/f61f62e1-6843-4c14-9beb-bc45dca43550:1)
at t.RealmsVm.evalCode (figma_app.7c9d3b9597f11149fb4ceeea484c16e1.min.js.br:613)
at t.RealmsVm.evalTopLevelCode (figma_app.7c9d3b9597f11149fb4ceeea484c16e1.min.js.br:613)
at figma_app.7c9d3b9597f11149fb4ceeea484c16e1.min.js.br:1157
I tried many possible ways to import a JSON file (as described here: https://mariusschulz.com/blog/importing-json-modules-in-typescript) but it does not seem to work.
How can I import my JSON file ?
Thanks