{"record":{"id":"433368dfbcc44c71","repo":"denoland/deno","slug":"no-lockfile-found-run-deno-install-first","errorCode":null,"errorMessage":"No lockfile found. Run `deno install` first.","messagePattern":"No lockfile found\\. Run `deno install` first\\.","errorType":"exception","errorClass":"AnyError","httpStatus":null,"severity":"error","filePath":"cli/tools/pm/why.rs","lineNumber":65,"sourceCode":"/// The string portion is the lockfile's key:\n/// - npm: e.g. \"express@4.22.1\" or \"react-dom@18.2.0_react@18.2.0\"\n/// - jsr: e.g. \"@std/async@1.2.0\"\ntype PkgId = (PackageKind, String);\n\nfn display_base(id: &PkgId) -> &str {\n  match id.0 {\n    PackageKind::Npm => strip_peer_suffix(&id.1),\n    PackageKind::Jsr => &id.1,\n  }\n}\n\npub async fn why(\n  flags: Arc<Flags>,\n  why_flags: WhyFlags,\n) -> Result<(), AnyError> {\n  let factory = CliFactory::from_flags(flags);\n  let lockfile = factory.maybe_lockfile().await?.cloned().ok_or_else(|| {\n    deno_core::anyhow::anyhow!(\"No lockfile found. Run `deno install` first.\")\n  })?;\n\n  // Workspace-declared root dependency requirements (from deno.json `imports`,\n  // `scopes`, `jsxImportSource`, etc., and from package.json\n  // `dependencies`/`devDependencies`). These are matched against the lockfile's\n  // `specifiers` map to decide which entries are user-imported roots vs.\n  // transitive resolutions that the lockfile also stores under `specifiers`\n  // (as JSR does for every dep req).\n  let workspace = factory.cli_options()?.workspace();\n  let mut root_reqs: HashSet<JsrDepPackageReq> = HashSet::new();\n  for deno_json in workspace.deno_jsons() {\n    root_reqs.extend(deno_json.dependencies(workspace.catalogs()));\n  }\n  for pkg_json in workspace.package_jsons() {\n    let deps = pkg_json.resolve_local_package_json_deps();\n    for dep in deps\n      .dependencies\n      .values()","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tools/pm/why.rs#L47-L83","documentation":"`deno why <package>` needs `deno.lock` to walk the dependency graph from your workspace root requirements down to transitive dependencies, and the command refuses to run when no lockfile exists. The lockfile is created by `deno install` (or any dependency-resolving command that saves it). Without it there is no resolved dependency tree to explain.","triggerScenarios":"Running `deno why chalk` in a fresh project that has never run `deno install`; running `deno why` from a directory that is not part of the workspace (so no deno.lock is found upward); running with `--no-lock`, which bypasses/ignores the lockfile.","commonSituations":"New clones where the contributor assumes deno.lock is generated on demand; running the command in the wrong terminal/cwd; projects that deliberately gitignore deno.lock (libraries), where every fresh checkout hits this.","solutions":["Run `deno install` once to resolve dependencies and write deno.lock, then re-run `deno why <pkg>`.","Verify you are in the workspace/package directory that owns the deno.json; the lockfile lives next to the workspace root.","If you intentionally have no lockfile (e.g. a library), `deno why` is unavailable; use `deno info <module>` to inspect resolutions instead.","Ensure you are not passing --no-lock."],"exampleFix":"# before\ndeno why @std/assert\n# error: No lockfile found. Run `deno install` first.\n\n# after\ndeno install\ndeno why @std/assert","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\nif (!existsSync(join(workspaceRoot, 'deno.lock'))) {\n  console.error('No lockfile found. Run `deno install` first.');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runDeno(['why', pkg]);\n} catch (e) {\n  if (String(e.message).includes('No lockfile found')) {\n    await runDeno(['install']); // bootstrap the lockfile, then retry\n    await runDeno(['why', pkg]);\n  }\n}","preventionTips":["Run `deno install` as the first step after cloning, before graph-inspection commands.","Commit deno.lock for applications so `deno why` works from any checkout.","Do not pass --no-lock when you intend to use lockfile-dependent commands."],"tags":["lockfile","pm","why","install","dependency-graph"],"backgroundTag":"missing-lockfile","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"}