denoland/deno · error · anyhow::Error
Invalid file path: {}
Error message
Invalid file path: {} What it means
Each input path is converted to a `file://` ModuleSpecifier before transpiling. `ModuleSpecifier::from_file_path` fails for paths that cannot become a valid file URL — an empty path or bytes that are not valid UTF-8 — and that failure surfaces as this error with the printed path.
Source
Thrown at cli/tools/transpile.rs:95
// Collect file paths and specifiers
let mut file_entries = Vec::new();
for file_path_str in files {
let file_path = cwd.join(file_path_str);
let media_type = MediaType::from_path(&file_path);
if !media_type.is_emittable() {
log::warn!(
"{} Skipping {} (not a TypeScript/JSX/TSX file)",
colors::yellow("Warning"),
file_path.display()
);
continue;
}
let specifier =
ModuleSpecifier::from_file_path(&file_path).map_err(|_| {
anyhow::anyhow!("Invalid file path: {}", file_path.display())
})?;
file_entries.push((file_path, specifier, media_type));
}
if file_entries.is_empty() {
anyhow::bail!(
"No emittable files found. Only TypeScript/JSX/TSX files can be transpiled."
);
}
// Transpile each file (TS -> JS)
for (file_path, specifier, media_type) in &file_entries {
let source_bytes = sys
.fs_read(file_path)
.with_context(|| format!("Failed to read {}", file_path.display()))?;
let source_code = String::from_utf8(source_bytes.into_owned())
.with_context(|| format!("{} is not valid UTF-8", file_path.display()))?;View on GitHub (pinned to 89f33cbef2)
Solutions
- Reproduce and inspect the argument (`printf '%s' "$arg" | od -c`) and fix or rename it to valid UTF-8
- Quote and null-check variables in the calling script so empty values fail before deno runs
- Add `set -u` (or equivalent) to catch unset variables in wrapper scripts
Example fix
# before deno transpile "$MAYBE_EMPTY" # after [ -n "$MAYBE_EMPTY" ] && deno transpile "$MAYBE_EMPTY"
Defensive patterns
Strategy: validation
Validate before calling
# bash: reject empty and non-UTF-8 args up front
for f in "$@"; do
[ -n "$f" ] || { echo "empty path argument" >&2; exit 1; }
printf '%s' "$f" | LC_ALL=C grep -qP '[\x80-\xFF]' && { echo "non-UTF-8 path: $f" >&2; exit 1; }
done
deno transpile "$@" Prevention
- Null-check every path variable before passing it to the CLI
- Avoid building filenames from raw byte data; normalize to UTF-8 first
- Run `locale` in build containers so glob expansion does not mangle filenames
When it happens
Trigger: A path argument that resolves to an empty string, or a filename containing non-UTF-8 bytes (e.g. from locale-mangled glob expansion or an unvalidated variable).
Common situations: Scripts that build paths from unvalidated environment variables; Unix filenames created with invalid encoding; empty-string expansion of `$FILE` reaching the CLI.
Related errors
- Declaration file {} is not under the current directory
- Invalid declaration file path
- Input file {} is not under the current directory. Use --outp
- No input files specified
- Cannot use --output with multiple input files. Use --outdir
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/138eca8d1ac3dd18.
Report an issue: GitHub.