{"record":{"id":"983852134ecaabd7","repo":"denoland/deno","slug":"could-not-load-or-create-deno-json","errorCode":null,"errorMessage":"Could not load or create deno.json","messagePattern":"Could not load or create deno\\.json","errorType":"exception","errorClass":"AnyError","httpStatus":null,"severity":"error","filePath":"cli/tools/pm/mod.rs","lineNumber":1443,"sourceCode":"    candidate.to_path_buf()\n  } else {\n    cwd.join(candidate)\n  };\n  deno_path_util::normalize_path(std::borrow::Cow::Owned(abs)).into_owned()\n}\n\nfn load_deno_config_for_link(\n  flags: &Arc<Flags>,\n  create_if_missing: bool,\n) -> Result<(CliFactory, ConfigUpdater), AnyError> {\n  if create_if_missing {\n    // For `link`, force creation of deno.json if missing; the `\"links\"` field\n    // lives there. We achieve this by claiming jsr specifiers are present,\n    // which makes `load_configs` materialise a deno.json when one isn't found.\n    let (cli_factory, _force_package_json, _npm_config, deno_config) =\n      load_configs(flags, || true, false, false)?;\n    let deno_config = deno_config.ok_or_else(|| {\n      deno_core::anyhow::anyhow!(\"Could not load or create deno.json\")\n    })?;\n    return Ok((cli_factory, deno_config));\n  }\n\n  // For `unlink`, never create a deno.json: if there isn't one, there's\n  // nothing to unlink. Load only an existing config so a failed unlink can't\n  // leave an empty deno.json behind.\n  let cli_factory = CliFactory::from_flags(flags.clone());\n  let options = cli_factory.cli_options()?;\n  let deno_config = match options.start_dir.member_deno_json() {\n    Some(deno_json) => ConfigUpdater::new(\n      ConfigKind::DenoJson,\n      url_to_file_path(&deno_json.specifier)?,\n    )?,\n    None => bail!(\"No deno.json found; there are no linked packages to unlink\"),\n  };\n  Ok((cli_factory, deno_config))\n}","sourceCodeStart":1425,"sourceCodeEnd":1461,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tools/pm/mod.rs#L1425-L1461","documentation":"`deno link` records entries in deno.json's `links` field, so it forces config creation by telling the config loader that jsr specifiers are present (which materializes a deno.json when none is found). If load_configs still returns no deno config after that, linking cannot proceed and this error fires.","triggerScenarios":"`deno link <path>` from a directory where the config loader can neither find nor create deno.json — package.json-only projects where creation is suppressed, an unwritable cwd, or discovery misdirected by config-path overrides — so deno_config stays None at cli/tools/pm/mod.rs:1443.","commonSituations":"Node-style projects without any deno.json; read-only directories or container mounts; running link in a scratch directory intending to configure later; a bad DENO_CONFIG_PATH-style override pointing somewhere unusable.","solutions":["Create deno.json yourself first: `deno init` or `echo '{}' > deno.json`, then run `deno link`","Confirm the current directory is writable and is where you want the config","Fix or remove config-path overrides that misdirect discovery"],"exampleFix":"# before\ndeno link ../shared   # no deno.json anywhere\n\n# after\necho '{}' > deno.json\ndeno link ../shared","handlingStrategy":"validation","validationCode":"try {\n  await Deno.stat('deno.json');\n} catch {\n  throw new Error('deno.json not found; create one (deno init) before deno link');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the config before running link in fresh directories","Ensure the working directory is writable","Keep config-path overrides pointing at real files"],"tags":["pm","link","deno-json","config"],"backgroundTag":"config-file-not-found","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}