{"record":{"id":"8d651e79d483f3b6","repo":"tauri-apps/tauri","slug":"failed-to-canonicalize-global-api-script-path","errorCode":null,"errorMessage":"failed to canonicalize global API script path","messagePattern":"failed to canonicalize global API script path","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-utils/src/plugin.rs","lineNumber":27,"sourceCode":"#[cfg(any(feature = \"build\", feature = \"build-2\"))]\nmod build {\n  use std::{\n    env::vars_os,\n    fs,\n    path::{Path, PathBuf},\n  };\n\n  const GLOBAL_API_SCRIPT_PATH_KEY: &str = \"GLOBAL_API_SCRIPT_PATH\";\n  /// Known file name of the file that contains an array with the path of all API scripts defined with [`define_global_api_script_path`].\n  pub const GLOBAL_API_SCRIPT_FILE_LIST_PATH: &str = \"__global-api-script.js\";\n\n  /// Defines the path to the global API script using Cargo instructions.\n  pub fn define_global_api_script_path(path: &Path) {\n    println!(\n      \"cargo:{GLOBAL_API_SCRIPT_PATH_KEY}={}\",\n      path\n        .canonicalize()\n        .expect(\"failed to canonicalize global API script path\")\n        .display()\n    )\n  }\n\n  /// Collects the path of all the global API scripts defined with [`define_global_api_script_path`]\n  /// and saves them to the out dir with filename [`GLOBAL_API_SCRIPT_FILE_LIST_PATH`].\n  ///\n  /// `tauri_global_scripts` is only used in Tauri's monorepo for the examples to work\n  /// since they don't have a build script to run `tauri-build` and pull in the deps env vars\n  pub fn save_global_api_scripts_paths(out_dir: &Path, mut tauri_global_scripts: Option<PathBuf>) {\n    let mut scripts = Vec::new();\n\n    for (key, value) in vars_os() {\n      let key = key.to_string_lossy();\n\n      if key == format!(\"DEP_TAURI_{GLOBAL_API_SCRIPT_PATH_KEY}\") {\n        tauri_global_scripts = Some(PathBuf::from(value));\n      } else if key.starts_with(\"DEP_\") && key.ends_with(GLOBAL_API_SCRIPT_PATH_KEY) {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri-utils/src/plugin.rs#L9-L45","documentation":"tauri_utils::plugin::define_global_api_script_path is called from a plugin's build.rs to register a global API script; it canonicalizes the given path (resolve to absolute, follow symlinks) and prints it as a cargo: directive. Path::canonicalize fails when the target file does not exist or an intermediate directory cannot be traversed.","triggerScenarios":"Calling define_global_api_script_path with a path to a file that does not exist yet (e.g. generated after build.rs runs), a typo, or a relative path resolved against an unexpected working directory (build scripts run in the package root).","commonSituations":"Plugin build script referencing a JS file that is generated later or not committed; relative paths not anchored to CARGO_MANIFEST_DIR.","solutions":["Ensure the script file exists before the call: commit it or generate it earlier in build.rs.","Anchor the path: Path::new(&env::var(\"CARGO_MANIFEST_DIR\").unwrap()).join(\"api.js\").","Log path.display() before the call to see what is actually resolved and fix typos."],"exampleFix":"// before\ndefine_global_api_script_path(Path::new(\"./generated/api.js\")); // not generated yet\n\n// after\nlet api = Path::new(&std::env::var(\"CARGO_MANIFEST_DIR\").unwrap()).join(\"api.js\");\nassert!(api.is_file(), \"missing {}\", api.display());\ndefine_global_api_script_path(&api);","handlingStrategy":"validation","validationCode":"// in the plugin build.rs, before registering\nif !path.is_file() {\n    panic!(\"global API script not found at {} - generate or commit it first\", path.display());\n}\ntauri_utils::plugin::define_global_api_script_path(&path);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Anchor script paths to CARGO_MANIFEST_DIR in build.rs.","Commit generated API scripts or generate them before define_global_api_script_path runs.","Log the resolved path in build.rs when debugging."],"tags":["tauri","build-script","plugin","global-api-script","path"],"backgroundTag":"file-not-found","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","contentChangedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}