code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

Path alias imports not being resolved in Figma Code Connect

Open jorgemasta opened this issue 2 months ago • 3 comments

Problem

Path aliases (@/*) in .figma.tsx files are not being transformed to the public package name. Relative imports work, but alias imports don't.

Current output:

"imports": [
  "import Alert from '@acme/package/Alert';",      // ✅ relative import works
  "import AlertTitle from '@/AlertTitle';"                        // ❌ alias import doesn't work
]

Expected output:

"imports": [
  "import Alert from '@acme/package/Alert';",
  "import AlertTitle from '@acme/package/AlertTitle';"
]

Setup

Alert.figma.tsx:

import Alert from './Alert';           // Works
import AlertTitle from '@/AlertTitle';  // Doesn't work

tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": { "@/*": ["./src/*"] }
  }
}

figma.config.json:

{
  "codeConnect": {
    "include": ["src/**/*"],
    "parser": "react",
    "importPaths": { "*": "@acme/package" },
    "paths": { "@/*": ["src/*"] }
  }
}

Configurations Tried

None of these work:

  • "importPaths": { "*": "@acme/package" }
  • "importPaths": { "*": "@acme/package/*" }
  • "importPaths": { "@/*": "@acme/package/*" }
  • Multiple combinations of the above with different paths configurations

Question

What's the correct figma.config.json setup to transform path aliases that match tsconfig.json?

Environment

  • Node: v22.15.0
  • @figma/code-connect: v1.3.6
  • OS: macOS

jorgemasta avatar Oct 14 '25 10:10 jorgemasta

Hi @jorgemasta. Thanks for the report. We'll investigate and see what we can improve here.

tweightman-figma avatar Oct 16 '25 10:10 tweightman-figma

@jorgemasta this should be fixed now in version 1.3.6 of the CLI. Could you please check if that's the case? Thanks!

ptomas-figma avatar Oct 23 '25 09:10 ptomas-figma

@ptomas-figma We were already using 1.3.6. I tried the new 1.3.7 version, and there are some improvements, but there's a remaining issue.

Now it's generating these imports (with the connect parse command):

      "imports": [
        "import Alert from '@acme/package/Alert';",
        "import AlertTitle from '@acme/package/index';"
      ],

Then, in Figma, we have:

import Alert from "@acme/package/Alert"
import AlertTitle from "@acme/package/index"
import AlertTitle from "@acme/package/AlertTitle"
import Button from "@acme/package/Button"

In Figma, it's almost correct since we have import AlertTitle from "@acme/package/AlertTitle", but import AlertTitle from "@acme/package/index" should not appear.

jorgemasta avatar Oct 23 '25 12:10 jorgemasta