tauri-apps/tauri · error
failed to read cwd
Error message
failed to read cwd
What it means
When the CLI runs as the Node package (TARGET=node), `tauri init` walks up from the current working directory to find node_modules/@tauri-apps/cli. std::env::current_dir() returns Err when the process's working directory no longer exists on disk (deleted or renamed), and this expect panics with 'failed to read cwd'.
Source
Thrown at crates/tauri-cli/src/init.rs:270
);
data.insert(
"window_title",
to_json(options.window_title.as_deref().unwrap_or("Tauri")),
);
data.insert("before_dev_command", to_json(options.before_dev_command));
data.insert(
"before_build_command",
to_json(options.before_build_command),
);
let mut config = serde_json::from_str(
&handlebars
.render_template(TAURI_CONF_TEMPLATE, &data)
.expect("Failed to render tauri.conf.json template"),
)
.unwrap();
if option_env!("TARGET") == Some("node") {
let mut dir = current_dir().expect("failed to read cwd");
let mut count = 0;
let mut cli_node_module_path = None;
let cli_path = "node_modules/@tauri-apps/cli";
// only go up three folders max
while count <= 2 {
let test_path = dir.join(cli_path);
if test_path.exists() {
let mut node_module_path = PathBuf::from("..");
for _ in 0..count {
node_module_path.push("..");
}
node_module_path.push(cli_path);
node_module_path.push("config.schema.json");
cli_node_module_path.replace(node_module_path);
break;
}
count += 1;View on GitHub (pinned to 52e4b6e71d)
Solutions
- Re-enter an existing directory: run `cd .` (fails, confirming the issue) then `cd ~/` and `cd` back into the recreated project directory.
- Restart the terminal session or reload the IDE window so it picks up a valid cwd.
- Re-run the tauri command from the project root after the directory exists again.
Example fix
# before: shell cwd was deleted, `npx tauri init` panics $ pwd && ls . /home/me/app (deleted) # after: reattach to a real directory first $ cd ~/ && cd /home/me/app # recreated directory $ npx tauri init
Defensive patterns
Strategy: validation
Validate before calling
// Node: confirm cwd still exists before invoking the CLI
import fs from "node:fs";
if (!fs.existsSync(process.cwd())) {
console.error("cwd was deleted; re-enter a valid directory");
process.exit(1);
} Prevention
- In scripts that delete/recreate directories, process.chdir() back to a recreated path before spawning tauri.
- Restart IDE terminals after deleting or renaming the project folder.
- Prefer absolute paths in automation over inheriting an assumed cwd.
When it happens
Trigger: Invoking the Node-based CLI (npx tauri ...) from a terminal or IDE whose cwd was deleted or recreated by another process while the session still pointed at the old inode.
Common situations: Running rm -rf on the project dir in one terminal then using a second terminal still cd'd there; VS Code integrated terminal after the folder was deleted/renamed; scripts that delete and recreate their own cwd.
Related errors
- Unable to write keypair
- Couldn't find capabilities directory at {}
- No file found in {} matching {}
- Failed to render template
- system clock is incorrect
AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20).
Data as JSON: /api/errors/76bde17dd86bb0b2.
Report an issue: GitHub.