Skip to content

Can we not use ESM imports in template files? #321

@mryechkin

Description

@mryechkin

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions