> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加一个 peer 依赖

要添加一个 npm 包作为 peer 依赖，使用 `--peer` 标志。

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun add @types/bun --peer
```

***

这将把该包添加到 `package.json` 中的 `peerDependencies`。

```json package.json icon="file-json" theme={"theme":{"light":"github-light","dark":"dracula"}}
{
  "peerDependencies": {
    "@types/bun": "^1.3.3" // [!code ++]
  }
}
```

***

运行 `bun install` 会默认安装 peer 依赖，除非在 `peerDependenciesMeta` 中标记为可选。

```json package.json icon="file-json" theme={"theme":{"light":"github-light","dark":"dracula"}}
{
  "peerDependencies": {
    "@types/bun": "^1.3.3"
  },
  "peerDependenciesMeta": {
    "@types/bun": { // [!code ++]
      "optional": true // [!code ++]
    } // [!code ++]
  }
}
```

***

完整的 Bun 包管理器文档请参见 [Docs > Package manager](/pm/cli/install)。
