tauri-apps/tauri · error

failed to parse plugin global API script paths

Error message

failed to parse plugin global API script paths

What it means

After reading the file list, `read_global_api_scripts` parses it with `serde_json::from_str::<Vec<PathBuf>>` and panics with this message on invalid JSON. The saved list is corrupted, truncated, or was written by an incompatible version.

Solutions

  1. Run `cargo clean` (or delete the out dir) to force regeneration of the file list
  2. Rebuild without interrupting the build process so the file is written atomically/completely
  3. Do not manually edit files under `target/`; regenerate them instead
  4. Align tauri CLI and tauri crate versions to the same release
Defensive patterns

Strategy: validation

Validate before calling

let s = std::fs::read_to_string(out_dir.join(GLOBAL_API_SCRIPT_FILE_LIST_PATH)).unwrap();
assert!(serde_json::from_str::<Vec<PathBuf>>(&s).is_ok(), "corrupted global API script list");

Prevention

When it happens

Trigger: Calling `read_global_api_scripts` when the `GLOBAL_API_SCRIPT_FILE_LIST_PATH` file contains non-JSON or structurally different content — e.g. a truncated write, hand-edited file, or content written by a different tauri-utils version with a different format.

Common situations: Interrupted builds leaving a partial file (CI killed mid-write); stale/corrupted incremental-build caches; manually editing files under `target/`; version mismatch between tauri CLI and tauri crates.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/251cbebb4a390309. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri-utils/src/plugin.rs:72

    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 460ec35447)