danqing
danqing

Reputation: 3668

Swift Package Manager error - The repository could not be found

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:

enter image description here

What's especially interesting is that while Xcode claims that the repo is not found, it can discover its version on the previous screen:

enter image description here

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

Answers (13)

John Scalo
John Scalo

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:

  • Remove the package dependencies from the project
  • Reset package caches
  • Add back the packages

Upvotes: 0

Pyry Jahkola
Pyry Jahkola

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

Fabi
Fabi

Reputation: 1

I had to uninstall Xcode and start all over again.

Upvotes: 0

Radu Ursache
Radu Ursache

Reputation: 1482

I had the same issues with Xcode 16, how I fixed it:

  1. Close Xcode
  2. Run rm -rf ~/Library/Caches/org.swift.swiftpm
  3. Run rm -rf ~/Library/Developer/Xcode/DerivedData/
  4. Check if your Git "Accounts" in Xcode preferences require changes (re-auth/ssh keys/etc)

OPTIONAL

Also try running

defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM YES

and restarting Xcode

Upvotes: 5

Wendell
Wendell

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

Pranav Kasetti
Pranav Kasetti

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>
  1. Open Terminal
  2. cd ~
  3. touch .netrc to create the .netrc file
  4. open .netrc
  5. Copy and Paste the contents above
  6. Save the file
  7. Close Xcode
  8. Clear the DerivedData folder
  9. Re-open Xcode

Upvotes: 1

Chad Parker
Chad Parker

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

realh
realh

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

Visal Rajapakse
Visal Rajapakse

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:

enter image description here

Upvotes: 0

Daniel Saidi
Daniel Saidi

Reputation: 6187

When this happened in Xcode 13.3, I just had to trigger the Reset Package Caches action in the Packages menu.

Xcode Reset Package Caches

Upvotes: 18

EBDOKUM
EBDOKUM

Reputation: 1846

For me, I just had to relaunch Xcode ¯\(ツ)

Upvotes: 9

Alqueraf
Alqueraf

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

izayl
izayl

Reputation: 500

clean DerivedData and add Package again

rm -rf ~/Library/Developer/Xcode/DerivedData/

Upvotes: 22

Related Questions