{"record":{"id":"76bde17dd86bb0b2","repo":"tauri-apps/tauri","slug":"failed-to-read-cwd-76bde1","errorCode":null,"errorMessage":"failed to read cwd","messagePattern":"failed to read cwd","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-cli/src/init.rs","lineNumber":270,"sourceCode":"    );\n    data.insert(\n      \"window_title\",\n      to_json(options.window_title.as_deref().unwrap_or(\"Tauri\")),\n    );\n    data.insert(\"before_dev_command\", to_json(options.before_dev_command));\n    data.insert(\n      \"before_build_command\",\n      to_json(options.before_build_command),\n    );\n\n    let mut config = serde_json::from_str(\n      &handlebars\n        .render_template(TAURI_CONF_TEMPLATE, &data)\n        .expect(\"Failed to render tauri.conf.json template\"),\n    )\n    .unwrap();\n    if option_env!(\"TARGET\") == Some(\"node\") {\n      let mut dir = current_dir().expect(\"failed to read cwd\");\n      let mut count = 0;\n      let mut cli_node_module_path = None;\n      let cli_path = \"node_modules/@tauri-apps/cli\";\n\n      // only go up three folders max\n      while count <= 2 {\n        let test_path = dir.join(cli_path);\n        if test_path.exists() {\n          let mut node_module_path = PathBuf::from(\"..\");\n          for _ in 0..count {\n            node_module_path.push(\"..\");\n          }\n          node_module_path.push(cli_path);\n          node_module_path.push(\"config.schema.json\");\n          cli_node_module_path.replace(node_module_path);\n          break;\n        }\n        count += 1;","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri-cli/src/init.rs#L252-L288","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: shell cwd was deleted, `npx tauri init` panics\n$ pwd && ls .\n/home/me/app   (deleted)\n\n# after: reattach to a real directory first\n$ cd ~/ && cd /home/me/app   # recreated directory\n$ npx tauri init","handlingStrategy":"validation","validationCode":"// Node: confirm cwd still exists before invoking the CLI\nimport fs from \"node:fs\";\nif (!fs.existsSync(process.cwd())) {\n  console.error(\"cwd was deleted; re-enter a valid directory\");\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["rust","tauri-cli","node","cwd","filesystem"],"backgroundTag":"working-directory-not-found","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}