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 字段。
deno add [OPTIONS] [packages]...Add dependencies to your configuration file.
deno add jsr:@std/path
You can also add npm packages:
deno add npm:react
Or multiple dependencies at once:
deno add jsr:@std/path jsr:@std/assert npm:chalk
Options Jump to heading
--allow-scripts<PACKAGE>optionalAllow running npm lifecycle scripts for the given packages
Note: Scripts will only be executed when using a node_modules directory (--node-modules-dir).
--dev, -DAdd the package as a dev dependency. Note: This only applies when adding to a package.json file.
--jsrassume unprefixed package names are jsr packages.
--lockfile-onlyInstall only updating the lockfile.
--npmassume unprefixed package names are npm packages.
--save-exactSave exact version without the caret (^).
Dependency management options Jump to heading
--frozen<BOOLEAN>optionalError out if lockfile is out of date.
--lock<FILE>optionalCheck the specified lock file. (If value is not provided, defaults to "./deno.lock").
--no-lockDisable auto discovery of the lock file.