denoland/deno · error

Could not get parent of {} ({})

Error message

Could not get parent of {} ({})

What it means

ConfigFile::dir_path() converts the deno.json/config-file specifier to a filesystem path and takes its parent directory to give relative paths a base. A path has no parent only when the config file sits directly at a filesystem root (/deno.json or C:\deno.json), and that exact case panics. Normal projects, nested dirs, and UNC paths all work; this is purely the root-directory edge case.

Source

Thrown at libs/config/deno_json/mod.rs:1852

          ConfigFileReadErrorKind::Deserialize {
            specifier: specifier.clone(),
            source: Box::new(err),
          }
          .into_box()
        },
      )?;

    Ok(Self {
      specifier,
      json: json.unwrap_or_default(),
    })
  }

  pub fn dir_path(&self) -> PathBuf {
    let path = url_to_file_path(&self.specifier).unwrap();
    match path.parent() {
      Some(parent) => parent.to_path_buf(),
      None => panic!(
        "Could not get parent of {} ({})",
        path.display(),
        self.specifier
      ),
    }
  }

  pub fn to_import_map_specifier(
    &self,
  ) -> Result<Option<Url>, ConfigFileError> {
    let Some(value) = self.json.import_map.as_ref() else {
      return Ok(None);
    };
    // try to resolve as a url
    if let Ok(specifier) = Url::parse(value) {
      if specifier.scheme() != "file" {
        return Err(ConfigFileError::OnlyFileSpecifiersSupported);
      }

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Move the config into a real directory (e.g. /app/deno.json) and adjust WORKDIR/paths
  2. Check for a stray root-level deno.json being picked up unintentionally (`deno info` shows which config is used)
  3. Pass an explicit --config pointing at the relocated file while the layout is fixed

Example fix

# before
COPY deno.json /
CMD ["deno", "run", "-A", "main.ts"]

# after
WORKDIR /app
COPY deno.json /app/
CMD ["deno", "run", "-A", "/app/main.ts"]
Defensive patterns

Strategy: validation

Validate before calling

# fail fast if the config file sits at the filesystem root
config="${CONFIG:-deno.json}"
dir="$(dirname "$(realpath "$config")")"
if [ "$dir" = "/" ]; then
  echo "refusing: config file at filesystem root" >&2
  exit 1
fi

Prevention

When it happens

Trigger: Running Deno with a config file located in a filesystem root: `deno run --config /deno.json app.ts`, a container image where the project was copied to /, or an accidental root-level deno.json being auto-discovered.

Common situations: Dockerfiles that COPY deno.json to / instead of a WORKDIR; throwaway containers mounting the config at the root; CI steps that cd to / and auto-discover a stray root-level config.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/31453bd97eb617f6. Report an issue: GitHub.