Add a dependency
To add an npm package as a dependency, use bun add.
terminal
bun add zodThis adds the package to dependencies in package.json. By default, Bun uses the ^ range specifier, which accepts future minor and patch versions.
package.json
{
"dependencies": {
"zod": "^3.0.0"
}
}To pin your project to the exact version you installed, use --exact. This adds the package to dependencies without the ^.
terminal
bun add zod --exactTo specify an exact version or a tag:
terminal
bun add zod@3.0.0
bun add zod@nextSee bun install.