tauri-apps/tauri · error

Tauri "Isolation" Pattern only supports relative or…

Error message

Tauri "Isolation" Pattern only supports relative or absolute (`/`) paths.

What it means

In the Tauri build-time HTML inlining, `inline_isolation` reads the isolation pattern's script file and embeds its content into the HTML. The `strip_prefix("/")` is wrapped in `expect` with this message, so it panics when the `src` path cannot have its leading `/` stripped — i.e. it is not a relative path and not a plain absolute `/`-rooted path (on Windows this includes drive-letter or UNC paths). The library only supports paths relative to the isolation dir or absolute paths rooted at `/`.

Solutions

  1. Use a path relative to the isolation directory (e.g. `isolation.js` or `../isolation/index.js`) instead of an absolute OS path
  2. On Windows, express the path as a `/`-rooted absolute path such as `/isolation/index.js` rather than `C:\...`
  3. Avoid UNC paths (`\\...`) for the isolation script source
  4. If you control the input, normalize/strip the drive or prefix before it reaches the inliner

Example fix

// before
<script src="C:\isolation\index.js"></script>
// after
<script src="/isolation/index.js"></script>
Defensive patterns

Strategy: validation

Validate before calling

let path = std::path::PathBuf::from(src);
if path.has_root() && !(path.starts_with("/") && path.strip_prefix("/").is_ok()) {
  panic!("isolation src must be relative or `/`-rooted: {}", src);
}

Type guard

fn is_supported_isolation_path(src: &str) -> bool {
  let p = std::path::PathBuf::from(src);
  !p.has_root() || p.strip_prefix("/").is_ok()
}

Prevention

When it happens

Trigger: Calling `inline_isolation` (via the HTML inliner during `tauri build`/`tauri dev` codegen) where the `<script src>` for the isolation pattern resolves to a `PathBuf` with a root that is not just `/` — e.g. `C:\isolation\index.js` or `\\server\share\x.js` on Windows, or any path whose `has_root()` is true but `strip_prefix("/")` fails.

Common situations: Windows developers configuring `app.security.pattern` isolation with an absolute Windows path; CI machines where an env var injects a drive-lettered path; paths built with `PathBuf::from("C:...")` instead of relative paths in tauri.conf.json.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at crates/tauri-utils/src/html2.rs:152

///
/// # Stability
///
/// This dependency [`dom_query`] for [`Document`] might receive updates in minor releases.
#[cfg(feature = "isolation")]
pub fn inline_isolation(document: &Document, dir: &std::path::Path) {
  let scripts = document.select("script[src]");

  for script in scripts.nodes() {
    let src = match script.attr("src") {
      Some(s) => s.to_string(),
      None => continue,
    };

    let mut path = std::path::PathBuf::from(src);
    if path.has_root() {
      path = path
        .strip_prefix("/")
        .expect("Tauri \"Isolation\" Pattern only supports relative or absolute (`/`) paths.")
        .into();
    }

    let file = std::fs::read_to_string(dir.join(path)).expect("unable to find isolation file");

    script.set_text(file);
    script.remove_attr("src");
  }
}

// TODO: Verify this, this is not found in the HTML spec, see https://github.com/tauri-apps/tauri/pull/14265#discussion_r2415396842
/// Normalize line endings in script content to match what the browser uses for CSP hashing.
///
/// According to the HTML spec, browsers normalize:
/// - `\r\n` → `\n`
/// - `\r`   → `\n`
pub fn normalize_script_for_csp(input: &[u8]) -> Vec<u8> {
  let mut output = Vec::with_capacity(input.len());

View on GitHub (pinned to 460ec35447)