denoland/deno · error · anyhow::Error

Unable to construct URL from the path of cwd: {}

Error message

Unable to construct URL from the path of cwd: {}

What it means

On REPL startup Deno converts the initial working directory to a `file://` directory URL (`Url::from_directory_path`) to resolve compiler options for the session. The conversion fails for paths the URL standard cannot represent — relative paths and certain Windows forms — so REPL startup aborts with this message including the offending path. In practice the OS cwd is absolute, so this signals an unusual launch environment.

Source

Thrown at cli/tools/repl/session.rs:354

            .aux_data
            .get("isDefault")
            .unwrap()
            .as_bool()
            .unwrap()
        );
        context_id = execution_context_created.context.id;
        break;
      }
    }
    assert_ne!(context_id, 0);

    let referrer =
      deno_core::resolve_path("./$deno$repl.mts", cli_options.initial_cwd())
        .unwrap();

    let cwd_url =
      Url::from_directory_path(cli_options.initial_cwd()).map_err(|_| {
        anyhow!(
          "Unable to construct URL from the path of cwd: {}",
          cli_options.initial_cwd().to_string_lossy(),
        )
      })?;
    let transpile_options = &compiler_options_resolver
      .for_specifier(&cwd_url)
      .transpile_options()?
      .transpile;
    let mut repl_session = ReplSession {
      internal_object_id: None,
      npm_installer,
      resolver,
      worker,
      session,
      state,
      context_id,
      referrer,
      notifications: Arc::new(Mutex::new(notification_rx)),

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Change into an existing absolute directory (cd ~) and start the REPL again
  2. If a wrapper spawns deno, make sure it passes a valid, existing absolute working directory
  3. Recreate or fix the directory the shell still points at
Defensive patterns

Strategy: validation

Validate before calling

# guard for wrappers/terminals spawning the deno REPL
case "$PWD" in
  /*) [ -d "$PWD" ] || { echo "cwd no longer exists: $PWD" >&2; exit 1; } ;;
  *) echo "cwd is not an absolute path: $PWD" >&2; exit 1 ;;
esac

Prevention

When it happens

Trigger: Starting `deno` (REPL) from a parent process that passes a relative or malformed cwd, a directory that was deleted/renamed out from under the shell, or exotic Windows paths (UNC edge cases, invalid characters).

Common situations: Editors or terminal wrappers spawning deno with a stale cwd after the project directory moved; scripts cd'd into a now-removed directory; test harnesses spawning processes with odd working directories.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/d0b93c9a286134c4. Report an issue: GitHub.