29

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?

3
  • 1
    Same problem for me today..
    – bezoadam
    Commented Nov 14, 2019 at 7:09
  • 2
    Update: fwiw the PanModal package starts to work after ~4 days, with no change in the repo whatsoever.
    – danqing
    Commented Nov 16, 2019 at 13:25
  • 3
    I ran into this today. Cleaning out derived data solved the issue. Commented Apr 5, 2020 at 15:00

8 Answers 8

29

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.

2
  • still necessary?
    – aehlke
    Commented Nov 10, 2023 at 18:23
  • Only thing that works for me. Thanks Commented Jan 24 at 20:45
21

clean DerivedData and add Package again

rm -rf ~/Library/Developer/Xcode/DerivedData/
4
  • Can OP mark this as solution please? Commented Mar 10, 2022 at 21:47
  • 1
    Funnily enough, this is what caused the error for me in the first place. Reset Package Caches fixed it.
    – jacksoor
    Commented Apr 29, 2022 at 14:18
  • This did NOT work for me (it won't work for all situations). I have used similar successfully at other times. Commented Nov 21, 2022 at 11:46
  • The above with rm -rf ~/Library/Caches/org.swift.swiftpm and restarting Xcode did work for me, but reloading libraries takes long. The problem occurred often starting with Xcode 15.3 for me. It was fully resolved with @pranav-kasetti s answer below: stackoverflow.com/a/76882207/1836024
    – thetrutz
    Commented Apr 2 at 16:39
19

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

8

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

1
  • 1
    Couldn't believe it, but also, that was what did the trick for me. Sure wish I could get those 2 hours back. Commented Oct 31, 2023 at 2:31
5

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).

1
  • 1
    this solution works for me. switch to 15.0 beta 1, add dependency then back to 14.3.1 Commented Aug 4, 2023 at 4:19
3

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
2

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
1

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

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.