Hi there, I'm started to get these error when I run figma-export use-confg command.
const stripAnsi = require('strip-ansi');
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/XXXXX/node_modules/strip-ansi/index.js from /Users/XXXXX/node_modules/ora/index.js not supported.
Instead change the require of /Users/XXXXX/node_modules/strip-ansi/index.js in /Users/XXXXX/node_modules/ora/index.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Users/XXXXX/node_modules/ora/index.js:7:19) {
code: 'ERR_REQUIRE_ESM'
}
const fs = require("fs");
const path = require("path");
const customOutput = async (pages) => {
const output = "./kit/primitives/Icon/resources";
fs.mkdirSync(output, { recursive: true });
console.log("OUTPUT", output);
try {
const Icons = [];
pages.forEach(({ name: pageName, components }) => {
console.log("PAGE", pageName);
components
.filter(({ name }) => name.startsWith("Icons/"))
.forEach(({ name, svg, id }) => {
const componentName = name.replaceAll("Icons/", "");
const filePath = path.resolve(output, `${componentName}.tsx`);
let p = filePath.split("/");
p.pop();
p = p.join("/");
fs.mkdirSync(p, { recursive: true });
svg = svg
.replaceAll(`fill-rule`, "fillRule")
.replaceAll(`clip-rule`, "clipRule")
.replaceAll(`fill="#121120"`, "")
.replaceAll(`fill="#000000"`, "")
.replaceAll(`<svg `, "<svg className={props.className}");
fs.writeFileSync(
filePath,
`
import React from "react";
export const Icon${componentName} = (props: { className?:string }) => {
return (${svg})
}
`,
);
Icons.push(componentName);
console.log("GENERATED", componentName);
});
});
const index = `
import dynamic from "next/dynamic";
export const RawIcon: Record<string, any> = {
${Icons.map(
(i) =>
`"${i}": dynamic<any>(() => import("./${i}").then(m=> m.Icon${i})) `,
).join(",\n")}
}
export type IconName = ${Icons.map((i) => `"${i}"`).join(" | ")}
`;
const filePath = path.resolve(output, `index.tsx`);
fs.writeFileSync(filePath, index);
console.log("GENERATED", "INDEX");
} catch (e) {
console.error(e);
}
};
module.exports = {
commands: [
[
"components",
{
fileId: "xxxx",
onlyFromPages: ["assets"],
transformers: [
require("@figma-export/transform-svg-with-svgo")({
plugins: ["removeViewBox", "removeDimensions", "cleanupIDs"],
}),
],
outputters: [customOutput],
},
],
],
};