figma / plugin-typings

Typings for the Figma Plugin API
MIT License
195 stars 45 forks source link

SyntaxError: possible import expression rejected around line {N} #312

Open eliot-liner opened 1 week ago

eliot-liner commented 1 week ago

Hello, Figam Developers.

I am developer of figma codegen (plugin). Thank you for developing this wonderful thing. 🥇

스크린샷 2024-10-09 오후 6 02 35

While looking for a place to report, I found a similar Pull Request and am posting the issue here. (ref. https://github.com/figma/plugin-typings/issues/36)

An error occurs if you include import( in the bundle file. I run prettier at runtime, but the service terminates unexpectedly due to an alert, so I cannot develop the plugin. Even if it is not a prettier, problems can occur in major libraries.

example bundle file

"use strict";
(() => {
  // src/index.ts
  figma.codegen.on("generate", () => {
    console.log("import(");
    return [];
  });
})();
//# sourceMappingURL=index.js.map

If you do not understand the situation, please ask a question. I would appreciate it if you could fix it :)

knguyen-figma commented 4 days ago

Hi @eliot-liner, this is expected behavior.

For now, you can get around this limitation by using string concatenation:

"use strict";
(() => {
  // src/index.ts
  const IMPORT_STRING = "im" + "port";
  figma.codegen.on("generate", () => {
    console.log(`${IMPORT_STRING}(`);
    return [];
  });
})();
eliot-liner commented 2 days ago

@knguyen-figma thanks for answer.

If this were my code, I could change it as you suggested, but it's in the comments in the bundle file of the library I'm using.

The library I am using at runtime is called “prettier”.

And I don't know why this is expected behavior. Shouldn't imports in comments or console logs be excluded from errors?