{"record":{"id":"ee74b0cd6299b625","repo":"denoland/deno","slug":"a-deno-json-file-could-not-be-found-or-created","errorCode":null,"errorMessage":"A deno.json file could not be found or created","messagePattern":"A deno\\.json file could not be found or created","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/tools/pm/approve_scripts.rs","lineNumber":52,"sourceCode":"\nstruct ScriptCandidate {\n  req: PackageReq,\n  specifier: String,\n  scripts: Vec<String>,\n}\n\npub async fn approve_scripts(\n  flags: Arc<Flags>,\n  approve_flags: ApproveScriptsFlags,\n) -> Result<(), AnyError> {\n  let mut factory = CliFactory::from_flags(flags.clone());\n  let mut options = factory.cli_options()?;\n  if options.start_dir.member_or_root_deno_json().is_none() {\n    factory = create_deno_json(&flags, options)?;\n    options = factory.cli_options()?;\n  }\n  let deno_json = options.workspace().root_deno_json().ok_or_else(|| {\n    anyhow::anyhow!(\"A deno.json file could not be found or created\")\n  })?;\n\n  let deno_json_path = url_to_file_path(&deno_json.specifier)?;\n\n  let mut config_updater =\n    ConfigUpdater::new(ConfigKind::DenoJson, deno_json_path.clone())?;\n\n  let allow_scripts_config = deno_json.to_allow_scripts_config()?;\n\n  let (mut allow_list, mut deny_list) = match allow_scripts_config.allow {\n    AllowScriptsValueConfig::All => {\n      log::info!(\n        \"Lifecycle scripts are already allowed for all npm packages in the workspace.\",\n      );\n      return Ok(());\n    }\n    AllowScriptsValueConfig::Limited(list) => (list, allow_scripts_config.deny),\n  };","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/cli/tools/pm/approve_scripts.rs#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n$ deno approve-scripts   # no deno.json anywhere\n# after\n$ echo '{}' > deno.json && deno approve-scripts","handlingStrategy":"validation","validationCode":"test -f deno.json || { echo 'no deno.json — creating one' >&2; echo '{}' > deno.json; }\ndeno approve-scripts","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a minimal deno.json at the repo root even in hybrid npm/Deno projects","Run approval commands from the workspace root"],"tags":["pm","config","deno-json","lifecycle-scripts"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}