denoland/deno · error · anyhow::Error
Input file {} is not under the current directory. Use --outp
Error message
Input file {} is not under the current directory. Use --output instead. What it means
With `--outdir`, the JS output path is outdir + (input with new extension) relative to cwd; `strip_prefix(cwd)` on the input fails when the input lives outside the current directory, and the error explicitly suggests `--output`, which accepts any path.
Source
Thrown at cli/tools/transpile.rs:555
cwd: &Path,
output: Option<&str>,
output_dir: Option<&str>,
media_type: MediaType,
) -> Result<PathBuf, AnyError> {
if let Some(output) = output {
// Explicit output file
return Ok(cwd.join(output));
}
let ext = js_extension_for_media_type(media_type);
let js_filename = input_path.with_extension(ext);
if let Some(outdir) = output_dir {
let outdir = cwd.join(outdir);
let relative = js_filename
.strip_prefix(cwd)
.map_err(|_| {
anyhow::anyhow!(
"Input file {} is not under the current directory. Use --output instead.",
input_path.display()
)
})?;
Ok(outdir.join(relative))
} else {
// Write alongside source file
Ok(js_filename)
}
}
View on GitHub (pinned to 89f33cbef2)
Solutions
- Run the command from a common ancestor directory of all inputs
- Use --output for a single file regardless of location: `deno transpile ../mod.ts -o out/mod.js`
- Omit --outdir entirely — output then lands next to each source file
Example fix
# before (cwd = packages/one) deno transpile --outdir dist ../shared/mod.ts # after deno transpile ../shared/mod.ts --output dist/mod.js
Defensive patterns
Strategy: validation
Validate before calling
# bash: same cwd guard as the declaration variant for f in "$@"; do case "$(realpath "$f")" in "$(pwd)"/*) ;; *) echo "$f outside cwd — use --output" >&2; exit 1;; esac done deno transpile --outdir dist "$@"
Prevention
- Run from a common ancestor directory when using --outdir
- Use --output for single files outside the tree
- Skip --outdir to emit next to sources when layout allows
When it happens
Trigger: `deno transpile --outdir dist ../shared/mod.ts` — an input file not under the current working directory combined with --outdir.
Common situations: Invoking from a nested directory with sources above it; CI steps that cd into an output directory before running the tool.
Related errors
- Declaration file {} is not under the current directory
- Cannot use --output with multiple input files. Use --outdir
- Invalid file path: {}
- Invalid declaration file path
- No input files specified
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/30d2be30a9f41853.
Report an issue: GitHub.