wasmerio/wasmer · error
no current dir name
Error message
no current dir name
What it means
In `wasmer init`'s `target_file` helper, when no target directory argument is given the CLI derives the package name from the current directory's canonicalized file stem. This error is raised when that derivation fails — canonicalization failed, the path has no file stem, or the stem is not valid UTF-8 — so no package name can be inferred.
Source
Thrown at lib/cli/src/commands/init.rs:213
Ok(())
}
fn target_file(&self) -> Result<(String, PathBuf), anyhow::Error> {
match self.out.as_ref() {
None => {
let current_dir = std::env::current_dir()?;
let package_name = self
.package_name
.clone()
.or_else(|| {
current_dir
.canonicalize()
.ok()?
.file_stem()
.and_then(|s| s.to_str())
.map(|s| s.to_string())
})
.ok_or_else(|| anyhow::anyhow!("no current dir name"))?;
Ok((package_name, current_dir.join(WASMER_TOML_NAME)))
}
Some(s) => {
std::fs::create_dir_all(s)
.map_err(|e| anyhow::anyhow!("{e}"))
.with_context(|| anyhow::anyhow!("{}", s.display()))?;
let package_name = self
.package_name
.clone()
.or_else(|| {
s.canonicalize()
.ok()?
.file_stem()
.and_then(|s| s.to_str())
.map(|s| s.to_string())
})
.ok_or_else(|| anyhow::anyhow!("no dir name"))?;
Ok((package_name, s.join(WASMER_TOML_NAME)))View on GitHub (pinned to 8c4b9ee9d3)
Solutions
- Pass an explicit directory/package name: `wasmer init my-app` so the name is not inferred.
- Or supply `--package-name <name>` to skip directory-based inference.
- `cd` out and back into the directory (or reopen the shell) to refresh a stale cwd, then retry.
- Rename the directory to a UTF-8, stem-bearing name if it has invalid bytes or an odd path shape.
Example fix
// before (cwd unresolvable) wasmer init // no current dir name // after wasmer init my-app
Defensive patterns
Strategy: validation
Validate before calling
fn can_infer_pkg_name_from_cwd() -> bool {
std::env::current_dir()
.ok()
.and_then(|d| d.canonicalize().ok())
.and_then(|d| d.file_stem().map(|_| ()))
.is_some()
}
// before `wasmer init` with no args:
assert!(can_infer_pkg_name_from_cwd(), "pass a name or --package-name"); Type guard
fn has_valid_stem(p: &std::path::Path) -> bool {
p.canonicalize().ok()
.and_then(|c| c.file_stem().and_then(|s| s.to_str()).map(|_| ()))
.is_some()
} Try / catch
match init_cmd.run_async().await {
Err(e) if e.to_string().contains("no current dir name") => {
eprintln!("Pass an explicit name: wasmer init my-app");
}
other => other?,
} Prevention
- Always pass an explicit name or --package-name in scripts and CI.
- Avoid running init from deleted/recreated directories; `cd` out and back.
- Use UTF-8 directory names without odd path components.
When it happens
Trigger: Running `wasmer init` (without a name/dir argument and without --package-name) from a directory whose canonical path cannot be resolved or whose file stem is missing/non-UTF-8, e.g. the cwd was deleted and recreated, or the path contains invalid UTF-8 bytes.
Common situations: Working from a deleted-then-recreated directory (stale cwd handle); non-UTF-8 directory names on Linux; invoking init in a context where canonicalize fails (broken mount, permission issue on a parent).
Related errors
- {e}
- {}
- no dir name
- Stopping as the directory is not empty
- Cannot pre-open the current directory twice: '--volume=.' mu
AI-assisted analysis of wasmerio/wasmer@8c4b9ee9d3 (2026-09-01).
Data as JSON: /api/errors/491c4ac2ca87519d.
Report an issue: GitHub.