Skip to main content
On this page

deno add

deno add 命令会将依赖项添加到项目的配置文件中。 它是 deno install [PACKAGES] 的别名。 有关 Deno 如何处理依赖项的更多信息,请参阅 模块和依赖项

示例 Jump to heading

从 JSR 和 npm 添加包:

>_
deno add @std/path npm:express

默认情况下,依赖项以插入符号 (^) 版本范围添加。使用 --save-exact 锁定到确切版本:

>_
deno add --save-exact @std/path

这会保存没有 ^ 前缀的依赖项(例如,1.0.0 而不是 ^1.0.0)。

将无前缀的包名视为 npm 包:

>_
deno add --npm express

依赖项存储位置 Jump to heading

如果你的项目有 package.json,npm 包将添加到 package.json 中的 dependencies。否则,所有包都会添加到 deno.json 中的 imports 字段。

Options Jump to heading

--allow-scripts Jump to heading

Allow running npm lifecycle scripts for the given packages Note: Scripts will only be executed when using a node_modules directory (--node-modules-dir).

--dev Jump to heading

Short flag: -D

Add the package as a dev dependency. Note: This only applies when adding to a package.json file.

--jsr Jump to heading

assume unprefixed package names are jsr packages.

--lockfile-only Jump to heading

Install only updating the lockfile.

--npm Jump to heading

assume unprefixed package names are npm packages.

--save-exact Jump to heading

Save exact version without the caret (^).

Dependency management options Jump to heading

--frozen Jump to heading

Error out if lockfile is out of date.

--lock Jump to heading

Check the specified lock file. (If value is not provided, defaults to "./deno.lock").

--no-lock Jump to heading

Disable auto discovery of the lock file.

Last updated on

你找到了你需要的东西吗?

编辑此页面
隐私政策