denoland/deno · error · anyhow::Error
Input file is not under the current directory. Use --output…
Error message
Input file {} is not under the current directory. Use --output instead. What it means
compute_output_path (cli/tools/transpile.rs:550-560) mirrors each input's directory structure under --outdir by stripping the current directory from the output .js path. An input that resolves outside cwd — typically an absolute path from another tree, or a working directory changed via -C while paths are given relative to elsewhere — cannot be stripped, so Deno raises this error and the message itself points you to --output.
Solutions
- Use --output <file> as the error suggests: single-file mode needs no relative structure.
- Run deno from a common ancestor so all inputs sit under the current directory.
- Pass inputs as paths relative to the actual cwd instead of absolute paths from another tree.
Example fix
# before $ cd app && deno transpile --outdir dist /opt/shared/mod.ts error: Input file /opt/shared/mod.ts is not under the current directory. Use --output instead. # after deno transpile --output dist/mod.js /opt/shared/mod.ts # or: cd /opt && deno transpile --outdir app/dist shared/mod.ts
Defensive patterns
Strategy: validation
Validate before calling
# Reject inputs outside cwd before choosing --outdir
for f in "$@"; do
p=$(realpath -m "$f")
[ "${p#$(pwd)}" != "$p" ] || { echo "$f is outside cwd — use --output"; exit 1; }
done
deno transpile --outdir dist "$@" Prevention
- Use --output for any input not under the current directory.
- Run builds from the repo root so --outdir can mirror the relative structure.
- Feed paths relative to the actual cwd instead of absolute paths from another tree.
When it happens
Trigger: deno transpile --outdir dist /opt/other/src/mod.ts (absolute input outside cwd); running with -C elsewhere while passing paths relative to the original directory.
Common situations: Build scripts that feed absolute paths collected from find/rg; monorepo builds invoked from a subdirectory; CI checkout layouts where sources live outside the declared cwd.
Related errors
- Declaration file is not under the current directory
- Invalid file path
- Invalid declaration file path
- Invalid file path
- invalid --output: dylib path has no file name
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/30d2be30a9f41853.
Report an issue: GitHub.
Appendix: 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 9ad36f7a2c)