Skip to main content
On this page

deno x

deno x 会从 npm 或 JSR 执行一个包,而不会将其永久安装。 它类似于 npm 生态系统中的 npx

安装 dx 别名 Jump to heading

为方便起见,你可以将 deno x 安装为一个独立的 dx 二进制文件,默认使用所有权限运行:

>_
deno x --install-alias

然后直接使用它:

>_
dx npm:create-vite my-app

你可以自定义别名名称:

>_
deno x --install-alias=denox

基本用法 Jump to heading

运行一个 npm 包:

>_
deno x npm:create-vite my-app

运行一个 JSR 包:

>_
deno x jsr:@std/http/file-server

将包与二进制文件分开指定 Jump to heading

一些 npm 包会暴露多个二进制文件——例如,typescript 同时提供 tsctsserver。从 Deno 2.8 开始,--package-p)可以让你 独立选择包和二进制文件,与 npx -p <package> <binary> 的约定一致:

>_
# 从 typescript 包中运行 `tsc`
deno x -p typescript tsc

# 锁定包版本
deno x -p typescript@5 tsc

之前的形式 deno x typescript/tsc 仍然有效。

工作原理 Jump to heading

deno x 会将包下载到全局缓存中(如果尚未缓存), 解析该包的二进制入口点,并执行它。该包不会被添加到你项目的 deno.jsonpackage.json 中。

使用 deno x 编写包 Jump to heading

deno x 如何找到要执行的内容取决于注册表:

  • npm 包 通过 package.json 中的 bin 字段暴露可运行的二进制文件。deno x npm:<package> 会运行该包的默认二进制文件,而 deno x -p <package> <binary>(或 deno x npm:<package>/<binary>)会在一个包提供多个二进制文件时选择其中一个。要让你自己的 npm 包可运行,请像为 npx 那样通过 bin 条目发布它。
  • JSR 包 通过让 deno x 指向一个在导入时会执行的导出来运行,例如 deno x jsr:@std/http/file-server。要让你自己的 JSR 包可运行,请将入口点作为模块导出,并用 import.meta.main 保护顶层副作用(这样该模块仍然可以作为库被导入),然后记录用户应运行的子路径,例如 deno x jsr:@you/tool/cli

如果你希望工具作为一个永久命令可用,而不是按需运行,请使用 deno install 安装它,或者将其编译为独立可执行文件。完整工作流程请参见 构建 CLI 应用,发布到 JSR 请参见 发布模块

权限 Jump to heading

执行的包将使用你指定的权限运行:

>_
deno x --allow-read --allow-net npm:serve .

或者授予所有权限:

>_
deno x -A npm:create-vite my-app
Command line usage:
deno x [OPTIONS] [SCRIPT_ARG]...

Execute a binary from npm or jsr, like npx

Type checking options Jump to heading

--check<CHECK_TYPE>optional
Jump to heading

Enable type-checking. This subcommand does not type-check by default If the value of "all" is supplied, remote modules will be included. Alternatively, the 'deno check' subcommand can be used.

--no-check<NO_CHECK_TYPE>optional
Jump to heading

Skip type-checking. If the value of "remote" is supplied, diagnostic errors from remote modules will be ignored.

Dependency management options Jump to heading

--cached-only
Jump to heading

Require that remote dependencies are already cached.

--frozen<BOOLEAN>optional
Jump to heading

Error out if lockfile is out of date.

Load import map file from local file or remote URL.

--lock<FILE>optional
Jump to heading

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

Disable auto discovery of the lock file.

Do not resolve npm modules.

--no-remote
Jump to heading

Do not resolve remote modules.

--node-modules-dir<MODE>optional
Jump to heading

Sets the node modules management mode for npm packages.

--node-modules-linker<MODE>
Jump to heading

Sets the linker mode for npm packages (isolated or hoisted).

--reload, -r<CACHE_BLOCKLIST>optional
Jump to heading

Reload source code cache (recompile TypeScript) no value Reload everything jsr:@std/http/file-server,jsr:@std/assert/assert-equals Reloads specific modules npm: Reload all npm modules npm:chalk Reload specific npm module.

--vendor<vendor>optional
Jump to heading

Toggles local vendor folder usage for remote modules and a node_modules folder for npm packages.

Options Jump to heading

--allow-scripts<PACKAGE>optional
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).

--cert<FILE>
Jump to heading

Load certificate authority from PEM encoded file.

Use this argument to specify custom conditions for npm package exports. You can also use DENO_CONDITIONS env var. .

Configure different aspects of deno including TypeScript, linting, and code formatting. Typically the configuration file will be called deno.json or deno.jsonc and automatically detected; in that case this flag is not necessary.

--env-file<FILE>optional
Jump to heading

Load environment variables from local file Only the first environment variable with a given key is used. Existing process environment variables are not overwritten, so if variables with the same names already exist in the environment, their values will be preserved. Where multiple declarations for the same environment variable exist in your .env file, the first one encountered is applied. This is determined by the order of the files you pass as arguments.

--install-alias<install-alias>optional
Jump to heading

Creates a dx alias so you can run dx instead of deno x .

--location<HREF>
Jump to heading

Value of globalThis.location used by some web APIs.

--minimum-dependency-age<minimum-dependency-age>
Jump to heading

(Unstable) The age in minutes, ISO-8601 duration or RFC3339 absolute timestamp (e.g. '120' for two hours, 'P2D' for two days, '2025-09-16' for cutoff date, '2025-09-16T12:00:00+00:00' for cutoff time, '0' to disable).

--no-config
Jump to heading

Disable automatic loading of the configuration file.

--package, -p<package>
Jump to heading

Package to install (use when the binary name differs from the package name).

--preload<FILE>
Jump to heading

A list of files that will be executed before the main module.

--require<FILE>
Jump to heading

A list of CommonJS modules that will be executed before the main module.

--seed<NUMBER>
Jump to heading

Set the random number generator seed.

--v8-flags<V8_FLAGS>optional
Jump to heading

To see a list of all available flags use --v8-flags=--help Flags can also be set via the DENO_V8_FLAGS environment variable. Any flags set with this flag are appended after the DENO_V8_FLAGS environment variable.

Assume confirmation for all prompts.

Debugging options Jump to heading

--inspect<HOST_PORT>optional
Jump to heading

Activate inspector on host:port [default: 127.0.0.1:9229]. Host and port are optional. Using port 0 will assign a random free port.

--inspect-brk<HOST_PORT>optional
Jump to heading

Activate inspector on host:port, wait for debugger to connect and break at the start of user script.

--inspect-wait<HOST_PORT>optional
Jump to heading

Activate inspector on host:port and wait for debugger to connect before running user code.

Last updated on

Did you find what you needed?

编辑此页面
Privacy policy