denoland/deno · error

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

Error message

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

What it means

`deno jupyter` builds a file:// URL from the process working directory using Url::from_directory_path, which only accepts absolute paths (and on Windows, well-formed drive/UNC paths). If the resolved initial cwd is relative or not representable as a directory URL, the kernel aborts with this message before creating the kernel worker.

Source

Thrown at cli/tools/jupyter/mod.rs:206

    .map_err(|_| anyhow!("REPL thread failed to start"))?;

  // --- Create the ZMQ kernel worker on the main thread ---------------
  let kernel_main_module = resolve_url_or_path(
    "./$deno$jupyter_kernel.mts",
    cli_options.initial_cwd(),
  )
  .unwrap();

  let (worker2, _) = create_single_test_event_channel();
  let TestEventWorkerSender {
    sender: _test_sender2,
    stdout: stdout2,
    stderr: stderr2,
  } = worker2;

  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 _ = cwd_url; // used later for test reporter if needed

  let mut kernel_worker = worker_factory
    .create_custom_worker(
      WorkerExecutionMode::Jupyter,
      kernel_main_module,
      vec![],
      vec![],
      permissions,
      vec![ops::jupyter::deno_jupyter_kernel::init()],
      Stdio {
        stdin: StdioPipe::inherit(),
        stdout: StdioPipe::file(stdout2),
        stderr: StdioPipe::file(stderr2),

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Launch deno jupyter from a stable absolute directory (verify with pwd -P first)
  2. Fix the caller: pass an absolute cwd when spawning the deno process
  3. On Windows, ensure the cwd is a normal drive path (like C:/projects/app)
  4. Re-sync PWD with reality (cd "$(pwd)") before starting the kernel

Example fix

// before
spawn('deno', ['jupyter'], { cwd: 'proj' }); // relative
// after
spawn('deno', ['jupyter'], { cwd: path.resolve('proj') });
Defensive patterns

Strategy: validation

Validate before calling

# bash: ensure an absolute, in-sync cwd before starting the kernel
cd "$(pwd -P)" || exit 2
case "$PWD" in
  /*) deno jupyter kernel ;;
  *) echo "cwd is not absolute: $PWD" >&2; exit 2 ;;
esac

Prevention

When it happens

Trigger: `deno jupyter` launched with a relative or malformed working directory: callers spawning deno with a relative cwd string, a stale $PWD after directory moves, or (on Windows) a cwd that is not a proper drive/UNC path.

Common situations: Editor/plugin integrations spawning deno with cwd like '.' or 'proj'; wrappers after cd-ing through deleted/symlinked directories; tools that pass a custom relative cwd to child processes.

Related errors


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