tauri-apps / tauri-apps/plugins-workspace

[bug] The system cannot find the file specified when launching the sidecar

Open
#2,139 1 comment 0 reactions 0 assignees View on GitHub
plugin: shell type: question
Dominant language
Rust
Stars
1.8k
Forks
602
Avg merge
4d 14h
Merged PRs (30d)
9

Description

### Describe the bug

I have a sidecar located in binaries/ that is not loaded correctly when called from javascript. It fails every time (as in the `proc = await cmd.spawn();` line throws an error) and the resulting error (which is only a string) is the very helpful message: `"The system cannot find the file specified. (os error 2)"`. I have been able to debug the frontend (which hasn't been very helpful, I can just see that it's failing when calling the rust), but have not been able to successfully debug the backend.

Several iterations ago I had this running with an absolute path calling the program using cmd.spawn() and it seemed to work but that was many iterations ago and I didn't record the results or code for posterity. I want to use the sidecar so that I can fully contain the launched process within the application and I don't need to manage child processes or anything.

My tauri.conf.json:
```json
{
...,
"externalBin": [
"binaries/RLL.Utility.DataOrchestrator"
]
}
```

My capabilities/default.json:
```json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": [
"main"
],
"permissions": [
"core:default",
"shell:allow-open",
"dialog:default",
{
"identifier": "shell:allow-spawn",
"allow": [
{
"sidecar": true,
"name": "binaries/RLL.Utility.DataOrchestrator"
}
]
},
{
"identifier": "shell:allow-kill",
"allow": [
{
"sidecar": true,
"name": "binaries/RLL.Utility.DataOrchestrator"
}
]
},
"shell:default"
]
}
```

My svelte code for spawning the sidecar:
```typescript
import { Child, Command } from "@tauri-apps/plugin-shell";

interface Props {
consoleHistory?: string;
}

let { consoleHistory = $bindable("") }: Props = $props();
let proc: Child | undefined = $state();

async function startListener() {
try {
const cmd = Command.sidecar("binaries/RLL.Utility.DataOrchestrator");

proc = await cmd.spawn();
console.log(proc);
} catch (err) {
console.log(JSON.stringify(err));
proc = undefined;
}
}

async function stopListener() {
await proc?.kill();
proc = undefined;
}

async function clearConsole() {
consoleHistory = "";
}
```

I also have the executable with the appropriate triplet appended in the src-tauri/binaries folder. The name of the executable is `RLL.Utility.DataOrchestrator-x86_64-pc-windows-msvc.exe` and the program builds and I see the resulting exe in the target/debug directory.

### Reproduction

1. Use the configuration I specified above.
2. Click the button on the frontend that executes the appropriate javascript.
3. Inspect the frontend devtools for the logged error.

### Expected behavior

The `command.spawn()` line to not throw an error and peacefully start the specified process.

### Full `tauri info` output

```text
[✔] Environment
- OS: Windows 10.0.19045 x86_64 (X64)
✔ WebView2: 131.0.2903.70
✔ MSVC:
- Visual Studio Build Tools 2019
- Visual Studio Community 2022
✔ rustc: 1.82.0 (f6e511eec 2024-10-15)
✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)
✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
- node: 20.10.0
- pnpm: 9.14.2
- npm: 10.2.3

[-] Packages
- tauri 🦀: 2.1.1
- tauri-build 🦀: 2.0.3
- wry 🦀: 0.47.2
- tao 🦀: 0.30.8
- @tauri-apps/api : 2.1.1
- @tauri-apps/cli : 2.1.0

[-] Plugins
- tauri-plugin-shell 🦀: 2.0.2
- @tauri-apps/plugin-shell : 2.0.1
- tauri-plugin-dialog 🦀: 2.0.3
- @tauri-apps/plugin-dialog : 2.0.1
- tauri-plugin-fs 🦀: 2.0.3
- @tauri-apps/plugin-fs : not installed!

[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../build
- devUrl: http://localhost:1420/
- framework: Svelte
- bundler: Vite
```

### Stack trace

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.