wasmerio/wasmer · error
Unable to determine the wasmer dir: {e}
Error message
Unable to determine the wasmer dir: {e} What it means
The CLI's DEFAULT_WASMER_DIR is resolved once at first use via dirs::data_dir (or similar). If that resolution fails and no WASMER_INSTALL_PREFIX was embedded at compile time (option_env!), the LazyLock panics with "Unable to determine the wasmer dir". The library needs a base directory for config/cache and cannot proceed without one.
Source
Thrown at lib/cli/src/config/mod.rs:22
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use url::Url;
use wasmer_backend_api::WasmerClient;
pub static GLOBAL_CONFIG_FILE_NAME: &str = "wasmer.toml";
pub static DEFAULT_PROD_REGISTRY: &str = "https://registry.wasmer.io/graphql";
/// The default value for `$WASMER_DIR`.
pub static DEFAULT_WASMER_DIR: LazyLock<PathBuf> =
LazyLock::new(|| match WasmerConfig::get_wasmer_dir() {
Ok(path) => path,
Err(e) => {
if let Some(install_prefix) = option_env!("WASMER_INSTALL_PREFIX") {
return PathBuf::from(install_prefix);
}
panic!("Unable to determine the wasmer dir: {e}");
}
});
/// The default value for `$WASMER_DIR`.
pub static DEFAULT_WASMER_CACHE_DIR: LazyLock<PathBuf> =
LazyLock::new(|| DEFAULT_WASMER_DIR.join("cache"));
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
pub struct WasmerConfig {
/// Whether or not telemetry is enabled.
#[serde(default)]
pub telemetry_enabled: bool,
/// Whether or not updated notifications are enabled.
#[serde(default)]
pub update_notifications_enabled: bool,
/// The registry that wasmer will connect to.View on GitHub (pinned to 8c4b9ee9d3)
Solutions
- Set the environment variable the resolver uses: export XDG_DATA_HOME (or HOME) to a writable path before running Wasmer.
- Rebuild Wasmer with the install prefix baked in: WASMER_INSTALL_PREFIX=/usr/local cargo build ...
- Check that the process user has a valid home directory (useradd -m) or run under a user with one.
- Alternatively pass --dir/-C wasmer dir flags or WASMER_DIR env where the CLI supports it to bypass the default.
Example fix
// before (systemd unit without HOME) [Service] ExecStart=/usr/local/bin/wasmer run app.wasm // after [Service] Environment=HOME=/var/lib/wasmer Environment=XDG_DATA_HOME=/var/lib/wasmer/share ExecStart=/usr/local/bin/wasmer run app.wasm
Defensive patterns
Strategy: validation
Validate before calling
# Shell: ensure the environment can resolve a wasmer dir before launching
if [ -z "${HOME:-}" ] && [ -z "${XDG_DATA_HOME:-}" ]; then
echo "Set HOME or XDG_DATA_HOME for wasmer" >&2
exit 1
fi Prevention
- Set XDG_DATA_HOME/HOME in systemd units, containers, and CI images.
- Build release artifacts with WASMER_INSTALL_PREFIX set.
- Create service users with home directories (useradd -m).
When it happens
Trigger: First access to DEFAULT_WASMER_DIR / DEFAULT_WASMER_CACHE_DIR in an environment where the XDG data dir cannot be determined (missing $HOME, no XDG_DATA_HOME, non-standard user setup), on a build compiled without the WASMER_INSTALL_PREFIX env var set.
Common situations: Running the wasmer CLI as a service/systemd unit with no HOME set; containers run with a stripped environment; headless CI images lacking XDG variables; custom builds where WASMER_INSTALL_PREFIX was not passed to cargo.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- not a `sys` backend!
- Unsupported backend kind {v:?}
- unimplemented operator {operator:?}
- wasmer_env_set_memory() is not supported
- cannot create debug directory: {}
AI-assisted analysis of wasmerio/wasmer@8c4b9ee9d3 (2026-09-01).
Data as JSON: /api/errors/9f27adac3ccebd30.
Report an issue: GitHub.