code-connect
code-connect copied to clipboard
Can we not use ESM imports in template files?
I'm following the docs for Template V2 and No Parser approach, and seems like the template files only work when using require and export default?
If I try the following (using import syntax), I get an error in Figma:
// url=...
import figma = 'figma';
const instance = figma.selectedInstance;
const errorText = instance.getString('text');
const code = `
import { Errors } from 'my-library';
<Errors errors={['${errorText}']} />
`;
export default {
example: figma.code(code),
id: 'Errors',
metadata: {
nestable: true,
},
};
Same situation if I use the module.exports syntax instead of export default. What's the reason for mixing this CommonJS and ESM syntax in the template files? Can we not just use pure ESM?