denoland/deno · error · AnyError
Unable to construct URL from the path of cwd
Error message
Unable to construct URL from the path of cwd: {} What it means
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.
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.
Example fix
# before: shell sits inside a deleted directory cd myproject && rm -rf myproject # (cwd gone) deno # error: Unable to construct URL from the path of cwd: ... # after cd ~ deno
Defensive patterns
Strategy: validation
Validate before calling
import { isAbsolute } from 'node:path';
import { accessSync, constants } from 'node:fs';
function assertUsableCwd(cwd: string): void {
if (!isAbsolute(cwd)) throw new Error(`cwd is not absolute: ${cwd}`);
accessSync(cwd, constants.X_OK); // throws if the directory vanished
} Type guard
function isUsableCwd(cwd: string | undefined): boolean {
if (!cwd) return false;
try {
accessSync(cwd, constants.X_OK);
return isAbsolute(cwd);
} catch {
return false;
}
} Try / catch
try {
await startDenoRepl();
} catch (e) {
if (String(e.message).includes('Unable to construct URL from the path of cwd')) {
// cd to a known-good absolute directory (e.g. homedir) and relaunch
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Both 'cert' and 'key' must be provided to enable HTTPS
- Cannot serve HTTP requests: either a `handler` or `options`…
- Cannot serve HTTP requests: handler must be a function…
- Could not open NUL device
- Couldn't find a deno.json, deno.jsonc, jsr.json or…
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/d0b93c9a286134c4.
Report an issue: GitHub.
Appendix: 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 9ad36f7a2c)