deno add command adds dependencies to your project’s configuration file.
Usage
Description
Adds packages to yourdeno.json imports or package.json dependencies. The command:
- Resolves the package to find the latest compatible version
- Updates your configuration file with the dependency
- Installs the package and updates the lockfile
Arguments
One or more packages to add. Format:
jsr:@scope/package- JSR packagenpm:package- npm package@scope/package@version- specific versionalias@jsr:@scope/package- custom import name
Options
Add as a development dependency (package.json only).
Default to npm packages when no prefix is specified.
Default to JSR packages when no prefix is specified.
Only update the lockfile, don’t install packages.
Save exact version instead of using a semver range (e.g.,
1.0.0 instead of ^1.0.0).Examples
Add a JSR package
deno.json:
Add an npm package
deno.json:
Add multiple packages
Add with custom alias
Add a specific version
Add exact version (no caret)
Add as dev dependency (package.json)
package.json:
Use npm as default registry
Only update lockfile
Configuration File Selection
deno.json
Preferred for JSR packages and most Deno projects:package.json
Used for npm packages when:package.jsonexists and nodeno.jsonpackage.jsonis closer to the current directory- Adding npm packages with
--npmflag
package.json, they’re converted to npm equivalents:
Version Resolution
- Without a version specifier, adds the latest compatible version
- Uses
^(caret) range by default for compatibility - Use
--save-exactto pin to exact versions - Supports
~(tilde) ranges:deno add jsr:@std/assert@~1.0.0
Aliases
Create custom import names:Notes
- If neither
deno.jsonnorpackage.jsonexist, adeno.jsonwill be created - The command automatically runs
deno installafter updating the config - JSR packages are preferred for Deno projects
- npm packages work seamlessly through Deno’s npm compatibility layer