wasmerio/wasmer · error

Cannot pre-open the current directory twice: '--volume=.' mu

Error message

Cannot pre-open the current directory twice: '--volume=.' must only be specified once

What it means

build_mapped_directories tracks whether the guest's current directory ('.') has already been pre-opened. Each --volume mapping with guest path '.' pre-opens the host directory as the guest root of the current dir; doing it twice would create two conflicting mappings for the same guest path, so the second one is rejected.

Source

Thrown at lib/cli/src/commands/run/wasi.rs:510

            let resolved_host = host.canonicalize().with_context(|| {
                format!(
                    "could not canonicalize path for argument '--volume {}:{}'",
                    host.display(),
                    guest,
                )
            })?;

            if guest == "/" && is_wasix {
                // Note: it appears we canonicalize the path before this point and showing the value of
                // `host` in the error message may throw users off, so we use a placeholder.
                tracing::warn!(
                    "Mounting on the guest's virtual root with --volume <HOST_DIR>:/ breaks WASIX modules' filesystems"
                );
            }

            let mapping = if guest == "." {
                if have_current_dir {
                    bail!(
                        "Cannot pre-open the current directory twice: '--volume=.' must only be specified once"
                    );
                }
                have_current_dir = true;

                let host = if host == Path::new(".") {
                    std::env::current_dir().context("could not determine current directory")?
                } else {
                    host.clone()
                };
                MappedDirectory {
                    host: resolved_host,
                    guest: if is_wasix {
                        MAPPED_CURRENT_DIR_DEFAULT_PATH.to_string()
                    } else {
                        "/".to_string()
                    },
                }

View on GitHub (pinned to 8c4b9ee9d3)

Solutions

  1. Remove the duplicate --volume=. mapping, keeping only one
  2. Merge duplicated volume flags from script/config sources into a single occurrence
  3. If you need extra host dirs, map them to distinct guest paths (e.g. --volume=/data:/data) instead of '.'

Example fix

// before
wasmer run app.wasm --volume . --volume ~/data:.
// after
wasmer run app.wasm --volume . --volume ~/data:/data
Defensive patterns

Strategy: validation

Validate before calling

fn validate_volumes(volumes: &[String]) -> Result<(), String> {
    let count = volumes.iter().filter(|v| {
        let guest = v.split(':').nth(1).unwrap_or(v);
        guest == "."
    }).count();
    if count > 1 { Err("'--volume=.' may only be specified once".into()) } else { Ok(()) }
}

Type guard

fn maps_current_dir(vol: &str) -> bool {
    let guest = vol.splitn(2, ':').nth(1).unwrap_or(vol);
    guest == "."
}

Try / catch

match wasmer_run_with_volumes(&volumes) {
    Err(e) if e.to_string().contains("Cannot pre-open the current directory twice") => {
        let deduped = dedupe_dot_volumes(&volumes);
        wasmer_run_with_volumes(&deduped)
    }
    other => other,
}

Prevention

When it happens

Trigger: Specifying `--volume .` or `--volume=<HOST>:.` (guest path ".") more than once in a single wasmer run invocation while building mapped dirs in prepare().

Common situations: Shell scripts that append --volume flags from multiple config sources (env var + config file), each adding '.'; copy-pasting volume flags from different examples; wrapping wasmer where defaults already pre-open '.' and the user adds another.

Related errors


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