anchor: Fresh project `anchor build` fails with "lock file version 4 requires `-Znext-lockfile-bump`"
Issue
Running anchor build or anchor test in a fresh project initialized with anchor-cli fails with the following:
error: failed to parse lock file at: /Users/{user}/{project_dir}/anchor/Cargo.lock
Caused by:
lock file version 4 requires `-Znext-lockfile-bump
Environment Details
Apple silicon (m1)
anchor --version
anchor-cli 0.30.1
cargo --version
cargo 1.85.0-nightly (4c39aaff6 2024-11-25)
solana --version
solana-cli 2.0.17 (src:7104d713; feat:607245837, client:Agave)
I ended up in this state after running cargo build-sbf --force-tools-install to resolve the error: not a directory: '.../solana-release/bin/sdk/sbf/dependencies/platform-tools/rust/lib' error as recommended here
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 32
Commits related to this issue
- "lock file version 4 requires -Znext-lockfile-bump" https://github.com/coral-xyz/anchor/issues/3392 — committed to Hsien-HsiuLiao/solana-developer-bootcamp-2024 by Hsien-HsiuLiao 2 years ago
You can fix this simply by changing the
versionfield ofCargo.lockas https://github.com/coral-xyz/anchor/issues/3393#issuecomment-2507904307 suggested:The reason why it happens is because Anchor v0.30 uses Solana v1.18, and Solana v1.18 depends on
rustc 1.75, but the new version (4) ofCargo.lockhas only been stabilized inrustc 1.78(as mentioned in https://github.com/rust-lang/cargo/issues/14655#issuecomment-2400237392).Solana build tools have recently been updated to use
rustc 1.79, which is available since Solana v2.1, and it’s also what themasterbranch of Anchor uses (https://github.com/coral-xyz/anchor/pull/3339).Anchor v0.31 (https://github.com/coral-xyz/anchor/pull/3259) will support Solana v2, meaning this issue will be resolved automatically. In the meantime, you can just use the fix mentioned at the beginning of this comment.
I get the same exact problem! Seems like they outsourced QA to the users 🤣
anchor is simply broken now. such issue shouldn’t exists at all. can’t finish a hello world now.
Why this issue is closed? The problem still exists… 😦
this does not work as re-running anchor build sets it back to 4…
Using the tutorial on the Solanas website and changing the version of the
Cargo.lockfile to3gives me this error which makes my head twist as i have rustc 1.83 installed. Sorry Im new, am i missing something obvious here?Hey there @Sandalo100, @notnullonline, @CarlTornberg, @HiPipilu, @waqasraza123, @kuchaguangjie, @6758f6, @n13 and @xcaptain - I hope you don’t mind the ping.
First of all, sorry to hear you’re having issues getting this to work. I’d like to make sure you can get started so feel free to reply with more context if the below doesn’t work for you.
Yesterday I spun up a new project and got the same issue. Here’s how I managed to get to a (consistently) working setup on my system.
1. Make sure to have rust 1.79.0 as the active version
I was on a higher version of Rust but this seemed to be the main problem. I tried a few versions and ended up using
1.79.0to get into a working state.I used
rustup default 1.79.0-aarch64-apple-darwin- you probably need to change this tag if you’re not on a machine with Apple Silicon. You can checkrustup showto see some of the other toolchains, this way you’ll probably figure out what tag you need.You should end up with these versions:
2. Be sure to be on version 2.0.21 of Solana (Agave client)
I installed the agave version of Solana as per the official docs.
You should get the following version:
If you have the agave tools installed but are on a different version, you can switch like so:
3. Be sure to be on version 0.30.1 of Anchor
4. Create a new project to check if the above works
If that last command doesn’t fail, you should be good to go.
5. Bonus: use
create-solana-programto scaffold a new project.The command uses create-solana-program to create a new project. It has a bunch of nice extra features to explore and I recommend you to check it out!
yep. for someone like me who is trying to build a sol program for the first time, the status “closed” doesn’t feel right. even if manually editing the lock file works for some, i think it should be pointed out that while this workaround can temporarily unblock you, it’s advisable to find a proper fix
this: lock file version 4 requires `-Znext-lockfile-bump.
I uninstalled everything, anchor, mocha, node, even linux because I use wsl ubuntu on windows… and in the end I got the same error… I’m losing my hair, I try everything (of course, helped by gemini and chatgpt and nothing) it only gets worse. Thanks friends
I get the same problem after set version = 3
Changing version of lockfile from 4 to 3 helped me. So if anything try that first and see if that fixes
For anyone new coming across this issue, this solution worked for me (apple silicon user)
I have never done Solana development before but the toolchain seems to be a complete mess - first impressions!
First I followed instructions from ChatGPT - nothing worked. Fair enough, I should have just used the official instructions, right?
They’re right here https://solana.com/docs/intro/installation
So I uninstalled everything, followed the official instructions, and after a ton of downloading, installing, and compiling, I got this error message on a brand new project
… an hour of downloading things anchor init anchor build “Error: -> lock file version 4 requires
-Znext-lockfile-bump”Not exactly confidence-inspiring.
Update: It seems like rust, solana, and anchor all have flexible version management… so therefore it seems one could simply write a bash script that contains the compatible versions of these tools in a table, and switches them all to compatible versions on a single command. The main issue is that the info which rust works with which solana and which anchor is all hidden somewhere in config files in binary code - it would save everyone a lot of headache to be able to verify that my currently active versions of these 3 tools are compatible with each other. like rust x.x works with solana x.x.x and anchor x.x.x…
add a new file
touch rust-toolchain.tomlthenIt worked for me, but I also had to change the version in the Cargo.lock .
https://github.com/coral-xyz/anchor/issues/3392#issuecomment-2508412018 - tried it, but it didn’t work for me either, thank you for sharing.
However, this worked:
I had a project that required 1.18.26 of solana tools. Then compiled it and stuff just worked. Maybe, it’ll help someone.
failed to parse lock file at fixed --> Caused by: lock file version 4 requires
-Znext-lockfile-bumpfixed with:
cargo build-sbf -- -Znext-lockfile-bumpRealise with real eyes!!
There might be a better solution:
agave-install init v2.1.7# replace the version with latest from githubcargo build-bpfagainRefer: https://stackoverflow.com/a/79349131/1568658
This answer works.
Edit:
And then it create more problems with the types in typescript if we change the version to 3.
I know,look this page https://github.com/solana-labs/solana/issues/34987 it works