tauri-apps/tauri · error
failed to write global API script
Error message
failed to write global API script
What it means
save_global_api_scripts_paths writes a JSON array of the collected global API script paths to <out_dir>/__global-api-script.js. The expect fires when fs::write fails: out_dir does not exist, is read-only, the disk is full, or permissions deny writing.
Source
Thrown at crates/tauri-utils/src/plugin.rs:59
let key = key.to_string_lossy();
if key == format!("DEP_TAURI_{GLOBAL_API_SCRIPT_PATH_KEY}") {
tauri_global_scripts = Some(PathBuf::from(value));
} else if key.starts_with("DEP_") && key.ends_with(GLOBAL_API_SCRIPT_PATH_KEY) {
let script_path = PathBuf::from(value);
scripts.push(script_path);
}
}
if let Some(tauri_global_scripts) = tauri_global_scripts {
scripts.insert(0, tauri_global_scripts);
}
fs::write(
out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH),
serde_json::to_string(&scripts).expect("failed to serialize global API script paths"),
)
.expect("failed to write global API script");
}
/// Read global api scripts from [`GLOBAL_API_SCRIPT_FILE_LIST_PATH`]
pub fn read_global_api_scripts(out_dir: &Path) -> Option<Vec<String>> {
let global_scripts_path = out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH);
if !global_scripts_path.exists() {
return None;
}
let global_scripts_str = fs::read_to_string(global_scripts_path)
.expect("failed to read plugin global API script paths");
let global_scripts = serde_json::from_str::<Vec<PathBuf>>(&global_scripts_str)
.expect("failed to parse plugin global API script paths");
Some(
global_scripts
.into_iter()
.map(|p| {View on GitHub (pinned to 52e4b6e71d)
Solutions
- Pass the cargo-provided OUT_DIR: std::env::var("OUT_DIR").unwrap().
- Create the directory first: std::fs::create_dir_all(out_dir)?.
- Free disk space or fix directory permissions in the build environment.
Example fix
// before
save_global_api_scripts_paths(Path::new("out"), None); // 'out' may not exist
// after
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
std::fs::create_dir_all(&out_dir).unwrap();
save_global_api_scripts_paths(&out_dir, None); Defensive patterns
Strategy: validation
Validate before calling
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR set by cargo"));
std::fs::create_dir_all(&out_dir)?;
tauri_utils::plugin::save_global_api_scripts_paths(&out_dir, None); Prevention
- Always pass cargo's OUT_DIR rather than a custom folder.
- create_dir_all on the out dir before writing.
- Keep build environments writable and monitored for disk space.
When it happens
Trigger: Calling save_global_api_scripts_paths with an out_dir that was never created (not the cargo-provided OUT_DIR), or writing on a read-only or full filesystem.
Common situations: Passing a custom directory instead of env OUT_DIR; CI sandboxes with restricted write access; disk exhaustion.
Related errors
- failed to write checked_features file
- failed to canonicalize global API script path
- failed to read plugin global API script paths
- Failed to write kotlin file
- failed to write proguard-tauri.pro
AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20).
Data as JSON: /api/errors/1348df898d5f6b11.
Report an issue: GitHub.