slint-ui/slint · error
write
Error message
write {}: {err} What it means
The Node.js binding build script fails when it cannot write the generated module file even though the directory exists. `write_if_changed` compares existing content and writes only on difference; `std::fs::write` failing panics with this message. The generated code (language module / window event module) cannot be produced, aborting the build.
Solutions
- Fix permissions/ownership of the generated file path (e.g. chown the target dir back to the build user)
- Check disk space; the write can fail on ENOSPC
- Remove any directory or read-only file occupying the generated file's path
- Run `cargo clean` and rebuild as a single non-root user
Example fix
// before: stale root-owned generated file # ls -l target/.../gen/js.rs -> owned by root // after sudo rm -f target/.../gen/js.rs && cargo build
Defensive patterns
Strategy: validation
Validate before calling
fs.accessSync(targetFile, fs.constants.W_OK);
if (fs.existsSync(targetFile) && fs.statSync(targetFile).isDirectory()) throw new Error('path is a directory'); Prevention
- Never run builds with sudo; chown target/ back if you did
- Watch for AV/editor locks on generated files during dev loops
- Monitor free disk space in CI
When it happens
Trigger: `std::fs::write(path, contents)` returns an error during `write_if_changed` — read-only file with the target name, permission loss between create_dir_all and write, disk full, or the target path is a directory.
Common situations: Generated file left owned by root from a previous sudo build; antivirus/editor locking the file on Windows; ENOSPC during long builds; a directory accidentally created at the generated file's path.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- create
- Cannot create output directory
- a setter belongs to a field
- failed ( )
- Components written in Rust can not get embedded yet.
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/a3f1c245eb6018f9.
Report an issue: GitHub.
Appendix: source
Thrown at api/node/build.rs:680
/// never sees them and they need no license header.
fn generated_header(sources: &[&str]) -> String {
format!(
"// AUTO-GENERATED by api/node/build.rs from {}. Do not edit.\n\n",
sources.join("\n// ")
)
}
/// Write `contents` only if it differs, so we don't invalidate downstream builds, and watch
/// the result so it regenerates when edited or removed by hand.
fn write_if_changed(path: &std::path::Path, contents: &str) {
println!("cargo:rerun-if-changed={}", path.display());
let dir = path.parent().expect("generated file has a parent directory");
std::fs::create_dir_all(dir).unwrap_or_else(|err| panic!("create {}: {err}", dir.display()));
let needs_write =
std::fs::read_to_string(path).map(|existing| existing != contents).unwrap_or(true);
if needs_write {
std::fs::write(path, contents)
.unwrap_or_else(|err| panic!("write {}: {err}", path.display()));
}
}
View on GitHub (pinned to bb937076de)