tauri-apps/tauri · error
failed to read plugin global API script paths
Error message
failed to read plugin global API script paths
What it means
read_global_api_scripts reads back <out_dir>/__global-api-script.js written during the build. The exists() check already passed, so the expect fires only on an IO-level read failure: the file was deleted between check and read, permission was lost, or the content is not valid UTF-8 (e.g. truncated by an interrupted build).
Source
Thrown at crates/tauri-utils/src/plugin.rs:70
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| {
fs::read_to_string(&p).unwrap_or_else(|e| {
panic!(
"failed to read plugin global API script {}: {e}",
p.display()
)
})
})
.collect(),
)
}
}View on GitHub (pinned to 52e4b6e71d)
Solutions
- Clean the artifacts: cargo clean (or delete the crate's OUT_DIR under target/) so the file is regenerated.
- Avoid running concurrent builds against the same target directory.
- If it persists, inspect the file: it must be a valid UTF-8 JSON array of paths.
Defensive patterns
Strategy: validation
Validate before calling
let p = out_dir.join(tauri_utils::plugin::GLOBAL_API_SCRIPT_FILE_LIST_PATH);
if let Ok(raw) = std::fs::read(&p) {
if std::str::from_utf8(&raw).is_err() {
std::fs::remove_file(&p).ok(); // force regeneration next build
}
} Prevention
- Do not share one target directory between concurrent builds.
- Clean the workspace after interrupted builds.
- Treat repeated failures here as corrupted artifacts and cargo clean.
When it happens
Trigger: A stale or half-written __global-api-script.js left in OUT_DIR by an interrupted or killed build; concurrent builds sharing one OUT_DIR; corrupted artifacts.
Common situations: Killing cargo mid-build and rebuilding into the same target dir; CI caching target/ with corrupted files; encoding corruption of the artifact.
Related errors
- failed to write global API script
- failed to write checked_features file
- failed to canonicalize global API script path
- 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/b70d7c5eb057b97f.
Report an issue: GitHub.