Reputation: 3668
I can't find any SO questions regarding this, but I've run into this problem twice. Basically when I'm trying to add a new package via SPM, I sometimes get the following error:
The repository could not be found. Make sure a valid repository exists at the specified location and try again.
For example, I'm trying to get PanModal (https://github.com/slackhq/PanModal) and I get the following:
What's especially interesting is that while Xcode claims that the repo is not found, it can discover its version on the previous screen:
What can be wrong here? Arguably PanModal just got SPM support, but that's 15 hours ago and I think that should be enough. Also, if I understand correct, SPM is decentralized so there shouldn't be cache or registry stuff that's in the way?
Upvotes: 45
Views: 27207
Reputation: 3401
Well this old by now but I ran into this and none of the above worked. What I was getting was a red x next to the package name with an error of "the repository could not be found" but only when trying to update the package. If I relaunched Xcode, it would show the older version no problem. And if I reset package caches at that point, it always "reset" to the older version.
What did work was:
Upvotes: 0
Reputation: 623
I faced this problem some time ago, back then fixed it by random removals of files under DerivedData
and ~/Library/Caches
. But it happened to me again just now that in MyProject
, attempting to update source packages one of them failed with an Xcode error like the following:
github.com: https://github.com/swiftlang/swift-argument-parser: The repository could not be found. Make sure a valid repository exists at the specified location and try again.
This time, the sufficient fix was the removal of the following two checkouts of the package dependency failing to update:
rm -rf ~/Library/Caches/org.swift.swiftpm/repositories/swift-argument-parser-*
rm -rf ~/Library/Developer/Xcode/DerivedData/MyProject-*/SourcePackages/repositories/swift-argument-parser-*
I think this was the correct workaround, too, because right after Xcode updating the package successfully, both directories reappeared, with a matching short commit suffix.
Upvotes: 0
Reputation: 1482
I had the same issues with Xcode 16, how I fixed it:
rm -rf ~/Library/Caches/org.swift.swiftpm
rm -rf ~/Library/Developer/Xcode/DerivedData/
OPTIONAL
Also try running
defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM YES
and restarting Xcode
Upvotes: 5
Reputation: 225
Try this command in the terminal, then relaunch Xcode. It resolved the error I encountered with Xcode.
defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM YES
Upvotes: 20
Reputation: 9925
It's possible to encounter the error when cloning for private Swift Packages. Log in with your GitHub account to authenticate Xcode when fetching the packages.
If your package is part of an organisation, remember to authenticate the Personal Access Token with SSO access to the organisation repositories on GitHub settings (under PATs section).
Note: We don't need SSH keys for authentication.
~/.netrc
contents:
machine api.github.com
login <Insert GitHub Username here>
password <Insert GH Personal Access Token here>
cd ~
touch .netrc
to create the .netrc fileopen .netrc
Upvotes: 1
Reputation: 462
I got this error while building a Swift command-line tool using SPM purely on the command-line (without Xcode). swift package clean
and swift package reset
didn't help, but I eventually added a .git
to the end of my package URL and that worked.
Error:
https://github.com/apple/swift-argument-parser
No error:
https://github.com/apple/swift-argument-parser.git
Upvotes: 6
Reputation: 1131
None of the previous answers worked for me. Instead I switched to XCode beta (currently version 15), and that seems to have cleared the issue up. It's not the first time I've had to switch to the beta (and back again when that broke).
Upvotes: 5
Reputation: 2042
An addition to EBDOKUM
's answer: Reopening Xcode works sometimes, but not always.
Opening the project using the .xcproject
or xcworkspace
may/may not fix package errors. Alternatively, something that worked extremely well for me was opening the XCode app, and opening the file using the "Open a project or file" option:
Upvotes: 0
Reputation: 6187
When this happened in Xcode 13.3, I just had to trigger the Reset Package Caches action in the Packages menu.
Upvotes: 18
Reputation: 1378
I had to disable HTTPS to SSH rewriting for Git.
Check inside your ~/.gitconfig
file if you have some line such as:
[url "[email protected]:"]
insteadOf = https://github.com/
If so comment it or remove when adding Swift Package Manager dependencies.
Upvotes: 31
Reputation: 500
clean DerivedData and add Package again
rm -rf ~/Library/Developer/Xcode/DerivedData/
Upvotes: 22