# resolve-import

Learn how to resolve import paths in source files.

This action rewrites import paths marked with a `?/` prefix in source files.

Templates often include source files that need to import modules from the target project, but the exact path depends on each project's structure and alias configuration. The `?/` prefix lets you write imports as glob patterns instead of hardcoded paths. The action searches the project for files matching the pattern, finds the one that exports the expected names, and replaces the import with the actual path — resolved through the project's alias configuration or as a relative path.

## Example

The following template downloads a component and resolves its imports. The example uses TypeScript, but the same approach applies to any supported language:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Component setup",
  "description": "Downloads a component and resolves its imports.",
  "actions": [
    {
      "name": "download",
      "source": "./code/hero.tsx",
      "destination": "src/components"
    },
    {
      "name": "resolve-import",
      "path": "src/components/hero.tsx"
    }
  ]
}
```

Suppose the downloaded file contains the following import:

**src/components/hero.tsx**

```tsx
import {cn} from "?/src/**/utils/*.ts";
```

The `?/` prefix marks the specifier as a wildcard pattern. The action searches the project for files matching `src/**/utils/*.ts` that export `cn`, and rewrites the import to the resolved path:

**src/components/hero.tsx**

```tsx
import {cn} from "@/lib/utils";
```

The final path depends on where the matching file lives and how the project's path aliases are configured.

## Properties

These are the supported properties:

- `name`: `string`

  The action identifier. Always `resolve-import` for this action.

- `path`: `string`

  The glob pattern matching the files to process.

  The action fails if no files match the pattern.

## Explore

- [Replace file content](/reference/cli/templates/actions/replace-file-content): Learn how to inject the resolved import.
- [Write file](/reference/cli/templates/actions/write-file): Learn how to write a file with imports.
- [Read file](/reference/cli/templates/actions/read-file): Learn how to read the target source file.
- [Format code](/reference/cli/templates/actions/format-code): Learn how to format after adding the import.
