wasmerio/wasmer · error

no dir name

Error message

no dir name

What it means

In `wasmer init`'s `target_file`, when a target directory `Some(s)` is given and no explicit package name was passed, the CLI derives the package name from `s.canonicalize().file_stem()`. This error is raised when that inference fails — canonicalization fails, there is no file stem, or the stem is not valid UTF-8.

Source

Thrown at lib/cli/src/commands/init.rs:230

                    })
                    .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)))
            }
        }
    }

    fn get_filesystem_mapping(include: &[String]) -> impl Iterator<Item = (String, PathBuf)> + '_ {
        include.iter().map(|path| {
            if path == "." || path == "/" {
                return ("/".to_string(), Path::new("/").to_path_buf());
            }

            let key = format!("./{path}");
            let value = PathBuf::from(format!("/{path}"));

            (key, value)
        })
    }

View on GitHub (pinned to 8c4b9ee9d3)

Solutions

  1. Provide the name explicitly: `wasmer init <dir> --package-name <name>`.
  2. Use a normal directory name (UTF-8, not `/` or `.`) so the stem can be inferred.
  3. Ensure the target path fully exists and is reachable (create parents first, fix symlinks).
  4. Retry from a shell where the path resolves normally (no broken mounts).

Example fix

// before
wasmer init /  // no dir name
// after
wasmer init / --package-name my-package
Defensive patterns

Strategy: validation

Validate before calling

fn stem_of(target: &Path) -> Option<String> {
    target.canonicalize().ok()
        .and_then(|c| c.file_stem().and_then(|s| s.to_str()))
        .map(|s| s.to_string())
}
// fall back if inference would fail:
let name = stem_of(dir).unwrap_or_else(|| "my-package".into());

Type guard

fn stem_is_inferable(p: &Path) -> bool {
    p.canonicalize().ok()
        .and_then(|c| c.file_stem().and_then(|s| s.to_str()).map(|_| ()))
        .is_some()
}

Try / catch

match init_in(dir).await {
    Err(e) if e.to_string().contains("no dir name") => {
        eprintln!("Supply --package-name; cannot infer from {:?}", dir);
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running `wasmer init <dir>` without `--package-name` where the directory path cannot be canonicalized or has no valid UTF-8 file stem (e.g. dir is `/` or `.` resolving to a stem-less path, non-UTF-8 bytes in the name, dir not yet existing under a broken mount).

Common situations: Passing odd targets like `/`, `.`, or paths ending in `..`; non-UTF-8 directory names; canonicalization failing due to symlinks into unavailable mounts; forgetting `--package-name` when using unusual paths.

Related errors


AI-assisted analysis of wasmerio/wasmer@8c4b9ee9d3 (2026-09-01). Data as JSON: /api/errors/1fdc521b9ed6ce43. Report an issue: GitHub.