Skip to main content
The deno add command adds dependencies to your project’s configuration file.

Usage

deno add [OPTIONS] <PACKAGES...>

Description

Adds packages to your deno.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
Packages can be from JSR (JavaScript Registry) or npm.

Arguments

PACKAGES
string[]
required
One or more packages to add. Format:
  • jsr:@scope/package - JSR package
  • npm:package - npm package
  • @scope/package@version - specific version
  • alias@jsr:@scope/package - custom import name

Options

--dev
boolean
default:"false"
Add as a development dependency (package.json only).
--npm
boolean
default:"false"
Default to npm packages when no prefix is specified.
--jsr
boolean
default:"false"
Default to JSR packages when no prefix is specified.
--lockfile-only
boolean
default:"false"
Only update the lockfile, don’t install packages.
--save-exact
boolean
default:"false"
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 add jsr:@std/assert
This adds to deno.json:
{
  "imports": {
    "@std/assert": "jsr:@std/assert@^1.0.0"
  }
}

Add an npm package

deno add npm:express
This adds to deno.json:
{
  "imports": {
    "express": "npm:express@^4.18.2"
  }
}

Add multiple packages

deno add jsr:@std/assert npm:chalk jsr:@oak/oak

Add with custom alias

deno add my-assert@jsr:@std/assert
This adds:
{
  "imports": {
    "my-assert": "jsr:@std/assert@^1.0.0"
  }
}

Add a specific version

deno add jsr:@std/[email protected]

Add exact version (no caret)

deno add --save-exact jsr:@std/assert
This adds:
{
  "imports": {
    "@std/assert": "jsr:@std/[email protected]"
  }
}

Add as dev dependency (package.json)

deno add --dev npm:typescript
This adds to package.json:
{
  "devDependencies": {
    "typescript": "^5.0.0"
  }
}

Use npm as default registry

deno add --npm chalk express

Only update lockfile

deno add --lockfile-only jsr:@std/assert

Configuration File Selection

deno.json

Preferred for JSR packages and most Deno projects:
{
  "imports": {
    "@std/assert": "jsr:@std/assert@^1.0.0",
    "express": "npm:express@^4.18.2"
  }
}

package.json

Used for npm packages when:
  • package.json exists and no deno.json
  • package.json is closer to the current directory
  • Adding npm packages with --npm flag
{
  "dependencies": {
    "express": "^4.18.2"
  },
  "devDependencies": {
    "typescript": "^5.0.0"
  }
}
For JSR packages in package.json, they’re converted to npm equivalents:
{
  "dependencies": {
    "@jsr/std__assert": "npm:@jsr/std__assert@^1.0.0"
  }
}

Version Resolution

  • Without a version specifier, adds the latest compatible version
  • Uses ^ (caret) range by default for compatibility
  • Use --save-exact to pin to exact versions
  • Supports ~ (tilde) ranges: deno add jsr:@std/assert@~1.0.0

Aliases

Create custom import names:
deno add assert@jsr:@std/assert
deno add $@npm:jquery
In your code:
import { assertEquals } from "assert";
import $ from "$";

Notes

  • If neither deno.json nor package.json exist, a deno.json will be created
  • The command automatically runs deno install after updating the config
  • JSR packages are preferred for Deno projects
  • npm packages work seamlessly through Deno’s npm compatibility layer

Build docs developers (and LLMs) love