Runtime
Bundler
Package Manager
Test Runner
Guides
Reference
Blog
Install Bun
Guides Package Manager

Add an optional dependency

To add an npm package as an optional dependency, use the --optional flag.

terminal
$ bun add zod --optional

This adds the package to optionalDependencies in package.json.

package.json
{
  "optionalDependencies": {
    "zod": "^3.0.0"
  }
}

See bun install.

On this page

No Headings