{"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":null,"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/89f33cbef296a2b287f323d42de54c871fa69c77/cli/tools/pm/mod.rs#L1425-L1461","documentation":"`deno link` stores entries in a \"links\" field of deno.json, so it forces config creation when none exists (by claiming JSR specifiers were found so config loading materializes a deno.json). This error means even the forced path produced no deno config — the directory cannot host one or discovery stopped at a non-Deno root.","triggerScenarios":"`deno link` run where config materialization fails: inside node_modules, a read-only cwd, or a workspace whose root is package.json-only.","commonSituations":"Linking from the wrong directory in monorepos; restricted/sandboxed filesystems in CI.","solutions":["Create deno.json manually (an empty {} suffices) and re-run deno link","Move to the intended package directory before linking","Check directory permissions if creation should have been possible"],"exampleFix":"# before\n$ cd /repo && deno link ../pkg   # /repo has no deno.json and none can be created\n# after\n$ cd /repo && echo '{}' > deno.json && deno link ../pkg","handlingStrategy":"validation","validationCode":"test -f deno.json || { echo 'deno link needs a deno.json — creating one' >&2; echo '{}' > deno.json; }\ndeno link \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run deno link from the package directory that should own the \"links\" field","Never run it inside node_modules or read-only checkouts"],"tags":["pm","link","config","deno-json"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}