# check-dependency

Learn how to check if packages are installed.

This action checks whether required packages are installed and stores the result in a variable.

This is helpful for framework detection or conditionally enabling features based on which packages are available in the project.

## Example

The following template checks whether Tailwind CSS is installed and prints the result:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Dependency check",
  "description": "Checks for Tailwind CSS.",
  "actions": [
    {
      "name": "check-dependency",
      "dependencies": [
        {
          "name": "tailwindcss",
          "optional": true
        }
      ],
      "result": {
        "tailwindcss": "hasTailwind"
      }
    },
    {
      "name": "print",
      "message": "Tailwind CSS: ${this.hasTailwind ? 'installed' : 'not installed'}"
    }
  ]
}
```

### Custom help

Without [`result`](#result-prop), the action fails for any missing non-optional dependency. The [`help`](#help-prop) property lets you customize the error with a message, suggestions, and links:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Next.js check",
  "description": "Verifies that Next.js is installed.",
  "actions": [
    {
      "name": "check-dependency",
      "dependencies": [
        {
          "name": "next",
          "version": ">=14"
        }
      ],
      "help": {
        "message": "This template requires Next.js 14 or later.",
        "suggestions": [
          "Install Next.js with `npx create-next-app@latest`."
        ],
        "links": [
          {
            "label": "Next.js docs",
            "url": "https://nextjs.org"
          }
        ]
      }
    }
  ]
}
```

## Properties

These are the supported properties:

- `name`: `string`

  The action identifier. Always `check-dependency` for this action.

- `dependencies`: `Array<object>`

  The list of packages to check.

  - `name`: `string`

    The package name to check, for example `next` or `tailwindcss`.

  - `version`: `string` (optional)

    A version range the installed version must satisfy.

    Uses the syntax supported by the project's package manager. When omitted, any installed version is accepted.

  - `optional`: `boolean` (optional) (default: false)

    Whether the dependency is optional.

    When `true`, a missing or incompatible package does not cause the action to fail.

- `result`: `object` (optional)

  A map of package names to variable names.

  Each variable receives a boolean indicating whether the corresponding package is installed and satisfies the version requirement.

  Dependencies listed in the result never cause the action to fail, because the purpose is to let subsequent actions decide what to do rather than failing immediately.

- `help`: `object` (optional)

  Custom error information displayed when a required dependency is missing.

  - `message`: `string`

    The error message displayed to the user.

  - `suggestions`: `Array<string>` (optional)

    A list of actionable suggestions to resolve the issue.

    Rendered as a bullet list.

  - `links`: `Array<object>` (optional)

    A list of reference links.

    - `label`: `string`

      The display text for the link.

    - `url`: `string`

      The URL to open.

## Explore

- [Add dependency](/reference/cli/templates/actions/add-dependency): Learn how to add a missing dependency.
- [Install](/reference/cli/templates/actions/install): Learn how to install project dependencies.
- [Test](/reference/cli/templates/actions/test): Learn how to branch based on conditions.
- [Fail](/reference/cli/templates/actions/fail): Learn how to abort with an error message.
