denoland/deno · error · anyhow::Error

Cannot use --output with multiple input files. Use --outdir

Error message

Cannot use --output with multiple input files. Use --outdir instead.

What it means

`--output` (-o) writes a single named file, so it accepts exactly one input. When `files.len() > 1` and `--output` is set, the tool rejects the combination and points at `--outdir`, which emits one output per input while preserving relative structure.

Source

Thrown at cli/tools/transpile.rs:37

use sys_traits::PathsInErrorsExt;

use crate::args::Flags;
use crate::args::SourceMapMode;
use crate::args::TranspileFlags;
use crate::factory::CliFactory;

pub async fn transpile(
  flags: Arc<Flags>,
  transpile_flags: TranspileFlags,
) -> Result<(), AnyError> {
  let files = &transpile_flags.files;

  if files.is_empty() {
    anyhow::bail!("No input files specified");
  }

  if files.len() > 1 && transpile_flags.output.is_some() {
    anyhow::bail!(
      "Cannot use --output with multiple input files. Use --outdir instead."
    );
  }

  if transpile_flags.declaration
    && transpile_flags.output.is_none()
    && transpile_flags.output_dir.is_none()
  {
    anyhow::bail!(
      "Cannot use --declaration without --output or --outdir. Declaration files must be written to disk."
    );
  }

  let is_stdout_mode = files.len() == 1
    && transpile_flags.output.is_none()
    && transpile_flags.output_dir.is_none();

  if is_stdout_mode

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Use --outdir instead: `deno transpile a.ts b.ts --outdir dist`
  2. Or keep -o and transpile each file in its own invocation: `for f in a.ts b.ts; do deno transpile "$f" -o "dist/$(basename "${f%.ts}").js"; done`
  3. If the inputs really are one module, merge them into a single entry file first

Example fix

# before
deno transpile src/a.ts src/b.ts --output dist/bundle.js
# after
deno transpile src/a.ts src/b.ts --outdir dist
Defensive patterns

Strategy: validation

Validate before calling

# bash: route based on input count
if [ "$#" -gt 1 ]; then deno transpile "$@" --outdir dist; else deno transpile "$@" --output dist/out.js; fi

Prevention

When it happens

Trigger: `deno transpile a.ts b.ts -o out.js` — two or more input files combined with a set `--output`.

Common situations: Adding a second source file to an existing one-file command that already used -o; build scripts that append inputs dynamically but keep a fixed output filename.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/a43708acafd37cdb. Report an issue: GitHub.