denoland/deno · error
No lockfile found. Run `deno install` first.
Error message
No lockfile found. Run `deno install` first.
What it means
`deno why` explains why a package is in the dependency graph by walking the lockfile (deno.lock). It hard-requires a lockfile; without one there are no resolutions to explain, hence the pointer to `deno install`.
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 89f33cbef2)
Solutions
- Run `deno install` to generate deno.lock, then retry deno why
- Make sure you are in the workspace directory the lockfile belongs to
- Remove --no-lock / re-enable the lockfile if you want deno why to work
- Restore deno.lock from version control if it was deleted
Example fix
# before $ deno why chalk Error: No lockfile found. Run `deno install` first. # after $ deno install && deno why chalk
Defensive patterns
Strategy: validation
Validate before calling
test -f deno.lock || { echo 'no lockfile — run deno install first' >&2; exit 2; }
deno why "$1" Prevention
- Commit deno.lock to version control
- Make `deno install` an explicit prerequisite step in docs and CI before any deno why usage
When it happens
Trigger: `deno why <pkg>` in a project that never ran `deno install`, with deno.lock deleted, or with the lockfile disabled (--no-lock or lockfile disabled in config).
Common situations: Fresh clones where install was skipped; CI jobs disabling the lockfile for speed; lockfiles gitignored or removed during cleanup.
Related errors
- A deno.json file could not be found or created
- Could not load or create deno.json
- Could not determine directory of '{}'
- Could not resolve package req '{}' from graph because it was
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/433368dfbcc44c71.
Report an issue: GitHub.