{"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":"AnyError","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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tools/pm/approve_scripts.rs#L34-L70","documentation":"`deno approve` (lifecycle-scripts permission management) edits the workspace root deno.json. If the start directory has no member deno.json it tries to create one via create_deno_json and re-resolves options; when a root deno.json still cannot be found afterwards, the command fails here — there is no config file to write permissions into.","triggerScenarios":"Running `deno approve ...` outside any Deno project: no deno.json discovered up the directory tree, and creation failed or was suppressed (unwritable directory, permissions, package.json-only project), leaving options.workspace().root_deno_json() None.","commonSituations":"Running the command in the wrong directory; read-only checkouts or mounts in CI; package.json-only Node projects where Deno will not synthesize a deno.json; config-path environment overrides misdirecting discovery.","solutions":["cd into the Deno project that owns the config and re-run","Create a config first: `deno init` or `echo '{}' > deno.json`, then retry","Check the directory is writable and not on a read-only filesystem","Verify any config-path environment overrides point at a real file"],"exampleFix":"# before\ndeno approve scripts   # run outside a project\n\n# after\necho '{}' > deno.json\ndeno approve scripts","handlingStrategy":"validation","validationCode":"async function hasDenoJson(start = Deno.cwd()): Promise<boolean> {\n  let d = start;\n  while (true) {\n    try { await Deno.stat(d + '/deno.json'); return true; }\n    catch {\n      const parent = d.split('/').slice(0, -1).join('/');\n      if (!parent || parent === d) return false;\n      d = parent;\n    }\n  }\n}\nif (!await hasDenoJson()) {\n  throw new Error('no deno.json up the tree; run inside a Deno project');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run workspace-mutating commands from the project root","Check write access in CI checkout steps","Keep a minimal deno.json even in hybrid Node projects"],"tags":["pm","deno-json","config","lifecycle-scripts","workspace"],"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"}