denoland/deno · error · AnyError

No lockfile found. Run `deno install` first.

Error message

No lockfile found. Run `deno install` first.

What it means

`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.

Solutions

  1. Run `deno install` once to resolve dependencies and write deno.lock, then re-run `deno why <pkg>`.
  2. Verify you are in the workspace/package directory that owns the deno.json; the lockfile lives next to the workspace root.
  3. If you intentionally have no lockfile (e.g. a library), `deno why` is unavailable; use `deno info <module>` to inspect resolutions instead.
  4. Ensure you are not passing --no-lock.

Example fix

# before
deno why @std/assert
# error: No lockfile found. Run `deno install` first.

# after
deno install
deno why @std/assert
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'node:fs';
import { join } from 'node:path';

if (!existsSync(join(workspaceRoot, 'deno.lock'))) {
  console.error('No lockfile found. Run `deno install` first.');
  process.exit(1);
}

Try / catch

try {
  await runDeno(['why', pkg]);
} catch (e) {
  if (String(e.message).includes('No lockfile found')) {
    await runDeno(['install']); // bootstrap the lockfile, then retry
    await runDeno(['why', pkg]);
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/433368dfbcc44c71. Report an issue: GitHub.

Appendix: source

Thrown at cli/tools/pm/why.rs:65

/// The string portion is the lockfile's key:
/// - npm: e.g. "express@4.22.1" or "react-dom@18.2.0_react@18.2.0"
/// - jsr: e.g. "@std/async@1.2.0"
type PkgId = (PackageKind, String);

fn display_base(id: &PkgId) -> &str {
  match id.0 {
    PackageKind::Npm => strip_peer_suffix(&id.1),
    PackageKind::Jsr => &id.1,
  }
}

pub async fn why(
  flags: Arc<Flags>,
  why_flags: WhyFlags,
) -> Result<(), AnyError> {
  let factory = CliFactory::from_flags(flags);
  let lockfile = factory.maybe_lockfile().await?.cloned().ok_or_else(|| {
    deno_core::anyhow::anyhow!("No lockfile found. Run `deno install` first.")
  })?;

  // Workspace-declared root dependency requirements (from deno.json `imports`,
  // `scopes`, `jsxImportSource`, etc., and from package.json
  // `dependencies`/`devDependencies`). These are matched against the lockfile's
  // `specifiers` map to decide which entries are user-imported roots vs.
  // transitive resolutions that the lockfile also stores under `specifiers`
  // (as JSR does for every dep req).
  let workspace = factory.cli_options()?.workspace();
  let mut root_reqs: HashSet<JsrDepPackageReq> = HashSet::new();
  for deno_json in workspace.deno_jsons() {
    root_reqs.extend(deno_json.dependencies(workspace.catalogs()));
  }
  for pkg_json in workspace.package_jsons() {
    let deps = pkg_json.resolve_local_package_json_deps();
    for dep in deps
      .dependencies
      .values()

View on GitHub (pinned to 9ad36f7a2c)