denoland/deno · error
A deno.json file could not be found or created
Error message
A deno.json file could not be found or created
What it means
The script-approval command needs a deno.json to record which npm lifecycle scripts may run. If no deno.json exists, Deno first tries to create one; this error means that after the attempt the workspace still has no root deno.json — creation was declined, failed, or the discovered root is not a deno.json.
Source
Thrown at cli/tools/pm/approve_scripts.rs:52
struct ScriptCandidate {
req: PackageReq,
specifier: String,
scripts: Vec<String>,
}
pub async fn approve_scripts(
flags: Arc<Flags>,
approve_flags: ApproveScriptsFlags,
) -> Result<(), AnyError> {
let mut factory = CliFactory::from_flags(flags.clone());
let mut options = factory.cli_options()?;
if options.start_dir.member_or_root_deno_json().is_none() {
factory = create_deno_json(&flags, options)?;
options = factory.cli_options()?;
}
let deno_json = options.workspace().root_deno_json().ok_or_else(|| {
anyhow::anyhow!("A deno.json file could not be found or created")
})?;
let deno_json_path = url_to_file_path(&deno_json.specifier)?;
let mut config_updater =
ConfigUpdater::new(ConfigKind::DenoJson, deno_json_path.clone())?;
let allow_scripts_config = deno_json.to_allow_scripts_config()?;
let (mut allow_list, mut deny_list) = match allow_scripts_config.allow {
AllowScriptsValueConfig::All => {
log::info!(
"Lifecycle scripts are already allowed for all npm packages in the workspace.",
);
return Ok(());
}
AllowScriptsValueConfig::Limited(list) => (list, allow_scripts_config.deny),
};View on GitHub (pinned to 89f33cbef2)
Solutions
- Create a deno.json first (echo '{}' > deno.json or deno init), then re-run
- Run the command inside the directory where the root deno.json should live
- Ensure the cwd is writable and the session is interactive if creation needs to prompt
Example fix
# before
$ deno approve-scripts # no deno.json anywhere
# after
$ echo '{}' > deno.json && deno approve-scripts Defensive patterns
Strategy: validation
Validate before calling
test -f deno.json || { echo 'no deno.json — creating one' >&2; echo '{}' > deno.json; }
deno approve-scripts Prevention
- Keep a minimal deno.json at the repo root even in hybrid npm/Deno projects
- Run approval commands from the workspace root
When it happens
Trigger: Running the approval command in a directory governed only by package.json where deno.json creation fails (non-interactive terminal, read-only cwd) or the created config does not become a workspace root.
Common situations: npm-centric repos adopting Deno incrementally; CI pipelines with no TTY where an interactive creation prompt cannot be answered; workspaces whose root config is package.json.
Related errors
- Could not load or create deno.json
- Missing name
- Missing name in config
- unsupported 'exports' shape in deno.json: expected a string
- {} is missing 'version' field
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/ee74b0cd6299b625.
Report an issue: GitHub.