tauri-apps/tauri · error
beforeDevCommand `{}` failed with exit code {}
Error message
beforeDevCommand `{}` failed with exit code {} What it means
When `beforeDevCommand` is configured in object form with `"wait": true`, `tauri dev` runs the script through `sh -c` (or `cmd /S /C` on Windows) in the frontend dir and waits for it. A non-zero exit code aborts dev mode, because the frontend server the app depends on never came up correctly.
Source
Thrown at crates/tauri-cli/src/dev.rs:195
let mut command = Command::new("sh");
command
.arg("-c")
.arg(&before_dev)
.current_dir(cwd)
.envs(env);
command
};
if wait {
let status = command.piped().map_err(|error| Error::CommandFailed {
command: format!(
"`{before_dev}` with `{}`",
if cfg!(windows) { "cmd /S /C" } else { "sh -c" }
),
error,
})?;
if !status.success() {
crate::error::bail!(
"beforeDevCommand `{}` failed with exit code {}",
before_dev,
status.code().unwrap_or_default()
);
}
} else {
command.stdin(Stdio::piped());
command.stdout(os_pipe::dup_stdout().unwrap());
command.stderr(os_pipe::dup_stderr().unwrap());
let child = SharedChild::spawn(&mut command)
.unwrap_or_else(|_| panic!("failed to run `{before_dev}`"));
let child = BEFORE_DEV.get_or_init(move || child);
std::thread::spawn(move || {
let status = child
.wait()
.expect("failed to wait on \"beforeDevCommand\"");View on GitHub (pinned to 52e4b6e71d)
Solutions
- Run the exact script manually in the frontend dir (e.g. `npm run dev`) and fix the underlying failure it reports
- If dependencies are missing, install them (`npm install`) first
- Check the script string for typos and that it matches a script defined in package.json; verify `wait: true` is what you want (string-form beforeDevCommand does not wait and would not raise this)
Example fix
// before (tauri.conf.json)
"beforeDevCommand": { "script": "npm run dev", "wait": true } // npm run dev exits 1
// after: fix package.json so `npm run dev` succeeds
"scripts": { "dev": "vite" } Defensive patterns
Strategy: validation
Validate before calling
# prove the dev script works before wiring it into tauri.conf.json cd frontend && npm ci && npm run dev & DEV_PID=$!; sleep 5 kill $DEV_PID 2>/dev/null # if it exited early, npm reports non-zero here
Prevention
- Test the script standalone in the frontend dir before putting it in `beforeDevCommand`
- Install node_modules after every fresh clone, before `tauri dev`
- Prefer the string form of `beforeDevCommand` unless you truly need exit-code gating from `wait: true`
When it happens
Trigger: `tauri dev` with `"beforeDevCommand": { "script": "npm run dev", "wait": true }` where the script fails: missing devDependencies, a syntax error, an already-in-use port, or a typo'd script name. Only the `wait: true` object form surfaces the exit code; the plain string form spawns without waiting.
Common situations: Fresh clones where `npm install` was not run before `tauri dev`; scripts that fail only on some machines (port conflicts, missing env vars); switching package managers without updating the script string.
Related errors
- {} `{}` failed with exit code {}
- failed to run `{before_dev}`
- Couldn't recognize the {} folder as a Tauri project. It must
- No external IP detected.
- failed to read missing addr file {}: {e}
AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20).
Data as JSON: /api/errors/c08769ae800cee7c.
Report an issue: GitHub.