DioxusLabs/dioxus · error · anyhow::Error

Failed to read name of css module file `{}`.

Error message

Failed to read name of css module file `{}`.

What it means

process_css_module derives a hashed output name from the CSS module's file name, first converting the OsStr file name to &str. If the name is not valid UTF-8, to_str() returns None and dx errors with the offending path before any CSS processing happens.

Source

Thrown at packages/cli/src/opt/css.rs:58

        )
    })?;

    Ok(())
}

pub(crate) fn process_css_module(
    css_options: &CssModuleAssetOptions,
    source: &Path,
    output_path: &Path,
) -> anyhow::Result<()> {
    let css = std::fs::read_to_string(source)?;

    // Collect the file hash name.
    let mut src_name = source
        .file_name()
        .and_then(|x| x.to_str())
        .ok_or_else(|| {
            anyhow!(
                "Failed to read name of css module file `{}`.",
                source.display()
            )
        })?
        .strip_suffix(".css")
        .ok_or_else(|| {
            anyhow!(
                "Css module file `{}` should end with a `.css` suffix.",
                source.display(),
            )
        })?
        .to_string();

    src_name.push('-');

    let hash = create_module_hash(source);
    let css = transform_css(css.as_str(), hash.as_str()).map_err(|error| {
        anyhow!(

View on GitHub (pinned to 393d190a80)

Solutions

  1. Rename the file to a valid UTF-8 name (plain ASCII is safest)
  2. Audit asset directories for undecodable names (ls | iconv -f utf-8 -t utf-8 surfaces them as errors)
  3. Keep asset generation tooling configured to emit UTF-8/ASCII file names
Defensive patterns

Strategy: validation

Validate before calling

// Guard asset collection before the build
fn assert_utf8_css_module_names(files: &[std::path::PathBuf]) {
    for f in files {
        assert!(f.file_name().and_then(|n| n.to_str()).is_some(), "non-UTF-8 file name: {f:?}");
    }
}

Type guard

fn is_utf8_path(p: &std::path::Path) -> bool { p.to_str().is_some() }

Prevention

When it happens

Trigger: A *.module.css asset whose file name contains non-UTF-8 bytes (e.g. written by a tool using a legacy 8-bit encoding) being processed by the dx asset pipeline.

Common situations: Files copied from old Windows shares or zip archives with mis-decoded names; unusual byte sequences in asset names on Linux/macOS.

Related errors


AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16). Data as JSON: /api/errors/a5133060dd8a8bc6. Report an issue: GitHub.