Adding packages
Usebun add to add a package to your project. The package is installed and saved to package.json.
Dev dependencies
Use-d (or --dev, -D, --development) to save to devDependencies:
Optional dependencies
Use--optional to save to optionalDependencies:
Peer dependencies
Use--peer to save to peerDependencies:
Exact versions
Use--exact (or -E) to pin to the resolved version rather than a range:
--exact, Bun writes a caret range (^18.2.0), which allows compatible updates.
Global packages
Use-g (or --global) to install a package globally without modifying the current project’s package.json. This is typically used for CLI tools.
bunfig.toml:
Git dependencies
Add a dependency from a public or private Git repository:To install a private repository, your system needs the appropriate SSH credentials configured.
Tarball dependencies
Add a package from a hosted.tgz file:
package.json:
Trusted dependencies
Bun does not run lifecycle scripts for installed dependencies by default. To allow scripts for a specific package, add it totrustedDependencies in package.json:
Removing packages
Usebun remove to uninstall a package and remove it from package.json:
bun remove updates the lockfile and removes the package from node_modules.