I've been trying to follow the tutorials provided in https://www.anchor-lang.com/docs to build smart contracts. However when I try to use anchor build/anchor test, I am facing this error. Failed to obtain package metadata: cargo metadata exited with an error

  • please replace screenshots with text in code blocks so the indexer can improve discoverability of this post
    – trent.sol
    Commented Aug 18, 2022 at 21:02

2 Answers 2


This sounds like a transient local network/internet connection related issue


What's happening in reality, is that your workspace is in the wrong place.

As far as i can see you are using wsl, but the folder you are working is from a mounted drive. This mnt/c/users is the path of your windows folder. In order for your Anchor to work properly you will need to work in another path.

You will need to build in the home path per example. Example path: \wsl.localhost\Ubuntu-20.04\home\username\

This will fix this error.

Have a great day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.