DioxusLabs/dioxus · error
Couldn't retrieve cargo metadata: {:?}
Error message
Couldn't retrieve cargo metadata: {:?} What it means
After dx create, post_create runs cargo_metadata::MetadataCommand in the new project's parent directory to detect an enclosing cargo workspace. A cargo_metadata::Error::CargoMetadata variant (parent is not a cargo project) is deliberately ignored, but every other failure — cargo missing from PATH, cargo failing to run, or a broken workspace manifest — bails with this message.
Source
Thrown at packages/cli/src/cli/create.rs:155
.file_name()
.context("Current path does not include directory name".to_string())?
.to_str()
.context("Current directory name is not a valid UTF-8 string".to_string())?
.to_string())
}
/// Post-creation actions for newly setup crates.
pub(crate) fn post_create(path: &Path, vcs: &Vcs) -> Result<()> {
let metadata = if let Some(parent_dir) = path.parent() {
match cargo_metadata::MetadataCommand::new()
.current_dir(parent_dir)
.exec()
{
Ok(v) => Some(v),
// Only 1 error means that CWD isn't a cargo project.
Err(cargo_metadata::Error::CargoMetadata { .. }) => None,
Err(err) => {
anyhow::bail!("Couldn't retrieve cargo metadata: {:?}", err)
}
}
} else {
None
};
// 1. Add the new project to the workspace, if it exists.
// This must be executed first in order to run `cargo fmt` on the new project.
let is_workspace = metadata.is_some();
metadata.and_then(|metadata| {
let cargo_toml_path = &metadata.workspace_root.join("Cargo.toml");
let cargo_toml_str = std::fs::read_to_string(cargo_toml_path).ok()?;
let relative_path = path.strip_prefix(metadata.workspace_root).ok()?;
let mut cargo_toml: toml_edit::DocumentMut = cargo_toml_str.parse().ok()?;
cargo_toml
.get_mut("workspace")?
.get_mut("members")?View on GitHub (pinned to 393d190a80)
Solutions
- Run cargo metadata in the parent directory yourself to see cargo's real error and fix the offending manifest
- Repair or remove the invalid parent/root Cargo.toml (workspace members list, invalid syntax)
- Verify cargo is installed and on PATH for the shell that runs dx (cargo --version)
- Create the project in a clean directory outside the broken workspace, then move it in afterwards
Defensive patterns
Strategy: validation
Validate before calling
# Verify the parent workspace is healthy before scaffolding into it (cd "$(dirname "$TARGET_DIR")" && cargo metadata --no-deps > /dev/null) || echo 'parent cargo metadata broken — fix before dx create'
Prevention
- Run cargo metadata in the target parent directory before dx create
- Keep workspace root manifests valid (syntax and members list)
- Ensure cargo is on PATH in the shell that launches dx
When it happens
Trigger: dx create inside a directory whose parent chain contains a Cargo.toml that cargo metadata cannot process (invalid TOML, unresolvable workspace members, bad path deps), or an environment where the cargo binary itself cannot execute.
Common situations: Scaffolding a new crate into an existing workspace with a syntax error in the root manifest; minimal CI containers without cargo on PATH; proxies breaking git-dependency resolution during metadata collection.
Related errors
- failed to parse toml at {}: {}
- Syntax Error in line {line} column {column}: {err}
- Package type '{invalid:?}' is not supported for bundle forma
- 1 issue found.
- Component '{}' not found in registry
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/45f4387a2e669e24.
Report an issue: GitHub.