{"record":{"id":"d0b93c9a286134c4","repo":"denoland/deno","slug":"unable-to-construct-url-from-the-path-of-cwd-d0b93c","errorCode":null,"errorMessage":"Unable to construct URL from the path of cwd: {}","messagePattern":"Unable to construct URL from the path of cwd: (.+?)","errorType":"exception","errorClass":"AnyError","httpStatus":null,"severity":"error","filePath":"cli/tools/repl/session.rs","lineNumber":354,"sourceCode":"            .aux_data\n            .get(\"isDefault\")\n            .unwrap()\n            .as_bool()\n            .unwrap()\n        );\n        context_id = execution_context_created.context.id;\n        break;\n      }\n    }\n    assert_ne!(context_id, 0);\n\n    let referrer =\n      deno_core::resolve_path(\"./$deno$repl.mts\", cli_options.initial_cwd())\n        .unwrap();\n\n    let cwd_url =\n      Url::from_directory_path(cli_options.initial_cwd()).map_err(|_| {\n        anyhow!(\n          \"Unable to construct URL from the path of cwd: {}\",\n          cli_options.initial_cwd().to_string_lossy(),\n        )\n      })?;\n    let transpile_options = &compiler_options_resolver\n      .for_specifier(&cwd_url)\n      .transpile_options()?\n      .transpile;\n    let mut repl_session = ReplSession {\n      internal_object_id: None,\n      npm_installer,\n      resolver,\n      worker,\n      session,\n      state,\n      context_id,\n      referrer,\n      notifications: Arc::new(Mutex::new(notification_rx)),","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tools/repl/session.rs#L336-L372","documentation":"When starting a REPL session, Deno converts the initial working directory into a file:// URL (`Url::from_directory_path`) to resolve compiler options relative to the cwd; if that conversion fails — the path is not absolute, empty, or (on Windows) not expressible as a file URL — REPL initialization aborts with this error naming the offending path. It fires before any user code runs.","triggerScenarios":"Starting the REPL when the process's current directory was deleted or replaced while the shell still sits in it (path no longer resolvable to a valid absolute URL); a relative or malformed cwd inherited from a parent process; on Windows, a cwd with a form the file-URL converter rejects. `Url::from_directory_path` returns Err for non-absolute paths.","commonSituations":"Terminal left in a directory removed by a build/clean step (`rm -rf build` while cd'd inside), then launching `deno`; launching deno from scripts that chdir to a relative path; container setups where PWD is set inconsistently with the actual cwd.","solutions":["`cd` into an existing directory (e.g. `cd ~` or `cd /`) and start deno again — a deleted cwd is the usual cause.","If launching programmatically, ensure the child process starts with an absolute, existing working directory (Node: `cwd: path.resolve(dir)`; Go: os.Chdir to abs path; Deno.Command: absolute cwd option).","Check shell hooks or wrappers that set PWD/DENO_DIR oddly; unset a stale PWD export.","On Windows, verify the cwd is a normal drive/UNC path rather than a device or virtual path."],"exampleFix":"# before: shell sits inside a deleted directory\ncd myproject && rm -rf myproject  # (cwd gone)\ndeno # error: Unable to construct URL from the path of cwd: ...\n\n# after\ncd ~\ndeno","handlingStrategy":"validation","validationCode":"import { isAbsolute } from 'node:path';\nimport { accessSync, constants } from 'node:fs';\n\nfunction assertUsableCwd(cwd: string): void {\n  if (!isAbsolute(cwd)) throw new Error(`cwd is not absolute: ${cwd}`);\n  accessSync(cwd, constants.X_OK); // throws if the directory vanished\n}","typeGuard":"function isUsableCwd(cwd: string | undefined): boolean {\n  if (!cwd) return false;\n  try {\n    accessSync(cwd, constants.X_OK);\n    return isAbsolute(cwd);\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  await startDenoRepl();\n} catch (e) {\n  if (String(e.message).includes('Unable to construct URL from the path of cwd')) {\n    // cd to a known-good absolute directory (e.g. homedir) and relaunch\n  }\n}","preventionTips":["Do not leave shells/agents inside directories that build scripts delete; cd out after rm -rf.","When spawning deno from scripts, always pass an absolute, existing working directory.","In long-lived tooling, verify the cwd still exists before each deno invocation."],"tags":["repl","cwd","working-directory","file-url","startup"],"backgroundTag":"invalid-working-directory","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}