denoland/deno · error
Could not load or create deno.json
Error message
Could not load or create deno.json
What it means
`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.
Source
Thrown at cli/tools/pm/mod.rs:1443
candidate.to_path_buf()
} else {
cwd.join(candidate)
};
deno_path_util::normalize_path(std::borrow::Cow::Owned(abs)).into_owned()
}
fn load_deno_config_for_link(
flags: &Arc<Flags>,
create_if_missing: bool,
) -> Result<(CliFactory, ConfigUpdater), AnyError> {
if create_if_missing {
// For `link`, force creation of deno.json if missing; the `"links"` field
// lives there. We achieve this by claiming jsr specifiers are present,
// which makes `load_configs` materialise a deno.json when one isn't found.
let (cli_factory, _force_package_json, _npm_config, deno_config) =
load_configs(flags, || true, false, false)?;
let deno_config = deno_config.ok_or_else(|| {
deno_core::anyhow::anyhow!("Could not load or create deno.json")
})?;
return Ok((cli_factory, deno_config));
}
// For `unlink`, never create a deno.json: if there isn't one, there's
// nothing to unlink. Load only an existing config so a failed unlink can't
// leave an empty deno.json behind.
let cli_factory = CliFactory::from_flags(flags.clone());
let options = cli_factory.cli_options()?;
let deno_config = match options.start_dir.member_deno_json() {
Some(deno_json) => ConfigUpdater::new(
ConfigKind::DenoJson,
url_to_file_path(&deno_json.specifier)?,
)?,
None => bail!("No deno.json found; there are no linked packages to unlink"),
};
Ok((cli_factory, deno_config))
}View on GitHub (pinned to 89f33cbef2)
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
Example fix
# before
$ cd /repo && deno link ../pkg # /repo has no deno.json and none can be created
# after
$ cd /repo && echo '{}' > deno.json && deno link ../pkg Defensive patterns
Strategy: validation
Validate before calling
test -f deno.json || { echo 'deno link needs a deno.json — creating one' >&2; echo '{}' > deno.json; }
deno link "$@" Prevention
- Run deno link from the package directory that should own the "links" field
- Never run it inside node_modules or read-only checkouts
When it happens
Trigger: `deno link` run where config materialization fails: inside node_modules, a read-only cwd, or a workspace whose root is package.json-only.
Common situations: Linking from the wrong directory in monorepos; restricted/sandboxed filesystems in CI.
Related errors
- A deno.json file could not be found or created
- Missing name
- Missing name in config
- unsupported 'exports' shape in deno.json: expected a string
- Could not determine directory of '{}'
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/983852134ecaabd7.
Report an issue: GitHub.