{"record":{"id":"7cc10166718b12cc","repo":"DioxusLabs/dioxus","slug":"unable-to-read-css-module-file","errorCode":null,"errorMessage":"Unable to read css module file","messagePattern":"Unable to read css module file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/manganis/manganis-macro/src/css_module.rs","lineNumber":85,"sourceCode":"\n    // Use the regular asset parser to generate the linker bridge.\n    let mut linker_tokens = quote! {\n        /// Auto-generated Manganis asset for css modules.\n        #[allow(missing_docs)]\n        const ASSET: manganis::Asset =\n    };\n    attribute.asset_parser.to_tokens(&mut linker_tokens);\n\n    let asset = match attribute.asset_parser.asset.as_ref() {\n        Ok(path) => path,\n        Err(err) => {\n            let err = err.to_string();\n            tokens.append_all(quote! { compile_error!(#err) });\n            return;\n        }\n    };\n\n    let css = std::fs::read_to_string(asset).expect(\"Unable to read css module file\");\n\n    let mut values = Vec::new();\n\n    let hash = create_module_hash(asset);\n    let class_mappings = get_class_mappings(css.as_str(), hash.as_str()).expect(\"Invalid css\");\n\n    // Generate class struct field tokens.\n    for (old_class, new_class) in class_mappings.iter() {\n        let as_snake = to_snake_case(old_class);\n\n        let ident = Ident::new(&as_snake, Span::call_site());\n        values.push(quote! {\n            pub const #ident: #struct_name_private::__CssIdent = #struct_name_private::__CssIdent { inner: #new_class };\n        });\n    }\n\n    // We use a PhantomData to prevent Rust from complaining about an unused lifetime if a css module without any idents is used.\n    tokens.extend(quote! {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/393d190a801ccb441d41923e232289b4f8a5c669/packages/manganis/manganis-macro/src/css_module.rs#L67-L103","documentation":"The css_module proc macro (behind the style! macro) resolves the referenced .css file and reads it with std::fs::read_to_string at compile time. Any IO failure — the file not existing at the resolved path, permission denied, or non-UTF-8 content — hits this expect and fails the compilation of the crate using the macro.","triggerScenarios":"style! { css: \"missing.css\" } where the resolved path (relative to the crate manifest) doesn't exist, was renamed/deleted, has restrictive permissions, or contains non-UTF-8 bytes.","commonSituations":"Renaming/moving css files without updating the macro path; rust-analyzer resolving the asset root differently; case-sensitivity differences after moving a repo from macOS/Windows to Linux; CI checkout missing the file.","solutions":["Verify the path relative to your crate root and create/restore the file","Use an explicit relative path: style! { css: \"./css/module.css\" }","Re-save the file with UTF-8 encoding if it came from another tool","Fix permissions or CI checkout; restart rust-analyzer / cargo clean after path fixes"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn css_module_readable(rel: &str) -> bool {\n    let path = std::path::Path::new(env!(\"CARGO_MANIFEST_DIR\")).join(rel);\n    path.exists() && std::fs::read_to_string(&path).is_ok()\n}\nassert!(css_module_readable(\"css/module.css\")); // in build.rs or a test","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep css files next to the components that use them and use explicit ./relative paths","Run a build (cargo check) after renaming/moving css files to catch stale macro paths","Keep css modules UTF-8 encoded","Watch case-sensitivity when moving repos across operating systems"],"tags":["manganis","css-modules","proc-macro","build","io"],"backgroundTag":null,"analyzedSha":"393d190a801ccb441d41923e232289b4f8a5c669","analyzedAt":"2026-08-16T11:27:45.815Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}