tauri-apps/tauri · error

failed to parse capabilities

Error message

failed to parse capabilities

What it means

Thrown at build time when the generated capabilities file was read but `serde_json::from_str` fails to deserialize it into the expected capabilities structure. The JSON is malformed or its schema does not match what the current tauri version expects — typically a truncated or stale file from an interrupted or mismatched-version build.

Solutions

  1. Delete the capabilities file or `cargo clean` and rebuild to regenerate it.
  2. Align the tauri CLI version with your tauri crate versions (npm/pnpm and Cargo.toml).
  3. Validate the JSON to confirm the corruption, then regenerate rather than editing it by hand.
  4. If defining capabilities, validate your capabilities/*.json files against the schema in your Tauri version.

Example fix

// before (truncated generated capabilities.json)
{"windows": {}
// after: regenerate via clean build
cargo clean && cargo tauri build
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const file = 'src-tauri/target/<profile>/build/<hash>/out/capabilities.json';
if (fs.existsSync(file)) {
  try {
    const caps = JSON.parse(fs.readFileSync(file, 'utf8'));
    if (!caps || typeof caps !== 'object') throw new Error('not an object');
  } catch (e) { console.error('stale/corrupted capabilities.json — cargo clean and rebuild'); }
}

Prevention

When it happens

Trigger: `tauri build`/`tauri dev` with a corrupted/truncated capabilities.json in the out dir, or one generated by an incompatible tauri CLI version whose capability schema differs.

Common situations: Interrupted builds (Ctrl-C during write); version mismatch between @tauri-apps/cli and tauri crates; manual edits to generated files; partial writes on disk-full.

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/5ce03dc451ad07d7. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri-codegen/src/context.rs:408

        crypto_keys: std::boxed::Box::new(::tauri::utils::pattern::isolation::Keys::new().expect("unable to generate cryptographically secure keys for Tauri \"Isolation\" Pattern")),
      })
    }
  };

  let acl_file_path = out_dir.join(ACL_MANIFESTS_FILE_NAME);
  let acl: BTreeMap<String, Manifest> = if acl_file_path.exists() {
    let acl_file =
      std::fs::read_to_string(acl_file_path).expect("failed to read plugin manifest map");
    serde_json::from_str(&acl_file).expect("failed to parse plugin manifest map")
  } else {
    Default::default()
  };

  let capabilities_file_path = out_dir.join(CAPABILITIES_FILE_NAME);
  let capabilities_from_files = if capabilities_file_path.exists() {
    let capabilities_json =
      std::fs::read_to_string(&capabilities_file_path).expect("failed to read capabilities");
    serde_json::from_str(&capabilities_json).expect("failed to parse capabilities")
  } else {
    Default::default()
  };
  let capabilities = get_capabilities(
    &config,
    capabilities_from_files,
    additional_capabilities.as_deref(),
  )
  .unwrap();

  let resolved = Resolved::resolve(&acl, capabilities, target).expect("failed to resolve ACL");

  let acl_tokens = map_lit(
    quote! { ::std::collections::BTreeMap },
    &acl,
    str_lit,
    identity,
  );

View on GitHub (pinned to 460ec35447)