{"id":"a089e7ddd7ccdb85","repo":"rust-lang/cargo","slug":"cannot-action-the-lock-file-lockfile-path-beca","errorCode":null,"errorMessage":"cannot {action} the lock file {lockfile_path} because {locked_flag} was passed to prevent this\nhelp: to generate the lock file without accessing the network, remove the {locked_flag} flag and use --offline instead.","messagePattern":"cannot (.+?) the lock file (.+?) because (.+?) was passed to prevent this\nhelp: to generate the lock file without accessing the network, remove the (.+?) flag and use --offline instead\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/lockfile.rs","lineNumber":64,"sourceCode":"    let (orig, mut out, lock_root) = resolve_to_string_orig(ws, resolve);\n\n    // If the lock file contents haven't changed so don't rewrite it. This is\n    // helpful on read-only filesystems.\n    if let Some(orig) = &orig {\n        if are_equal_lockfiles(orig, &out, ws) {\n            return Ok(false);\n        }\n    }\n\n    if let Some(locked_flag) = ws.gctx().locked_flag() {\n        let lockfile_path = lock_root.as_path_unlocked().join(LOCKFILE_NAME);\n        let action = if lockfile_path.exists() {\n            \"update\"\n        } else {\n            \"create\"\n        };\n        let lockfile_path = lockfile_path.display();\n        anyhow::bail!(\n            \"cannot {action} the lock file {lockfile_path} because {locked_flag} was passed to prevent this\\n\\\n             help: to generate the lock file without accessing the network, \\\n             remove the {locked_flag} flag and use --offline instead.\"\n        );\n    }\n\n    // While we're updating the lock file anyway go ahead and update its\n    // encoding to whatever the latest default is. That way we can slowly roll\n    // out lock file updates as they're otherwise already updated, and changes\n    // which don't touch dependencies won't seemingly spuriously update the lock\n    // file.\n    let default_version = ResolveVersion::with_rust_version(ws.lowest_rust_version());\n    let current_version = resolve.version();\n    let next_lockfile_bump = ws.gctx().cli_unstable().next_lockfile_bump;\n    tracing::debug!(\"lockfile - current: {current_version:?}, default: {default_version:?}\");\n\n    if current_version < default_version {\n        resolve.set_version(default_version);","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/lockfile.rs#L46-L82","documentation":"write_pkg_lockfile is about to change Cargo.lock but a locked flag (--locked or --frozen) is active, which forbids any lockfile mutation. It bails at lockfile.rs:64, reporting whether it would have created or updated the file, and hints to drop the flag and use --offline if the concern was network access.","triggerScenarios":"Running a build/publish/fetch with `--locked` or `--frozen` when Cargo.lock is missing or out of date relative to Cargo.toml (dependencies changed, versions drifted).","commonSituations":"CI with `--frozen` after bumping a dependency in Cargo.toml without running `cargo update`; lockfile not committed; different lockfile between teammates.","solutions":["Regenerate the lockfile locally without the flag: `cargo generate-lockfile` (or `cargo update`), commit it, then re-run with --locked/--frozen.","If you only want to avoid network use, drop --locked/--frozen and use `--offline` instead.","In CI, run `cargo fetch --locked` first; if that fails, rebuild the lockfile in a prior step."],"exampleFix":"# before\n$ cargo build --frozen\nerror: cannot update the lock file Cargo.lock because --frozen was passed ...\n\n# after - refresh lockfile, commit, then freeze\n$ cargo update\n$ git add Cargo.lock && git commit -m \"refresh lockfile\"\n$ cargo build --frozen\n# or, avoid network without freezing:\n$ cargo build --offline","handlingStrategy":"validation","validationCode":"# In CI: refresh the lockfile while unfrozen, then verify it freezes:\ncargo generate-lockfile\ngit diff --exit-code Cargo.lock || cargo update\n# now safe to use --locked/--frozen downstream:\ncargo fetch --locked\ncargo build --frozen","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Commit Cargo.lock and refresh it whenever Cargo.toml deps change.","Prefer --offline over --locked when the concern is network access.","Add a CI step that regenerates the lockfile before the --frozen build."],"tags":["lockfile","locked","frozen","ci","offline"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}