{"record":{"id":"31453bd97eb617f6","repo":"denoland/deno","slug":"could-not-get-parent-of","errorCode":null,"errorMessage":"Could not get parent of {} ({})","messagePattern":"Could not get parent of (.+?) \\((.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libs/config/deno_json/mod.rs","lineNumber":1852,"sourceCode":"          ConfigFileReadErrorKind::Deserialize {\n            specifier: specifier.clone(),\n            source: Box::new(err),\n          }\n          .into_box()\n        },\n      )?;\n\n    Ok(Self {\n      specifier,\n      json: json.unwrap_or_default(),\n    })\n  }\n\n  pub fn dir_path(&self) -> PathBuf {\n    let path = url_to_file_path(&self.specifier).unwrap();\n    match path.parent() {\n      Some(parent) => parent.to_path_buf(),\n      None => panic!(\n        \"Could not get parent of {} ({})\",\n        path.display(),\n        self.specifier\n      ),\n    }\n  }\n\n  pub fn to_import_map_specifier(\n    &self,\n  ) -> Result<Option<Url>, ConfigFileError> {\n    let Some(value) = self.json.import_map.as_ref() else {\n      return Ok(None);\n    };\n    // try to resolve as a url\n    if let Ok(specifier) = Url::parse(value) {\n      if specifier.scheme() != \"file\" {\n        return Err(ConfigFileError::OnlyFileSpecifiersSupported);\n      }","sourceCodeStart":1834,"sourceCodeEnd":1870,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/config/deno_json/mod.rs#L1834-L1870","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Move the config into a real directory (e.g. /app/deno.json) and adjust WORKDIR/paths","Check for a stray root-level deno.json being picked up unintentionally (`deno info` shows which config is used)","Pass an explicit --config pointing at the relocated file while the layout is fixed"],"exampleFix":"# before\nCOPY deno.json /\nCMD [\"deno\", \"run\", \"-A\", \"main.ts\"]\n\n# after\nWORKDIR /app\nCOPY deno.json /app/\nCMD [\"deno\", \"run\", \"-A\", \"/app/main.ts\"]","handlingStrategy":"validation","validationCode":"# fail fast if the config file sits at the filesystem root\nconfig=\"${CONFIG:-deno.json}\"\ndir=\"$(dirname \"$(realpath \"$config\")\")\"\nif [ \"$dir\" = \"/\" ]; then\n  echo \"refusing: config file at filesystem root\" >&2\n  exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In Dockerfiles, set WORKDIR before COPY so project files never land in /","Keep deno.json inside a real project directory, never at / or a drive root","Use `deno info` to confirm which config file Deno actually discovered"],"tags":["deno-json","config","path","filesystem-root"],"backgroundTag":"config-file-at-filesystem-root","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}