111

When I integrate a local package in my Xcode project everything is fine initially but when i switch branches and want to run the app Xcode gives me the compile error Missing package product <package name>. When I quit Xcode and re-open it everything is fine again. Any idea what this can be? An Xcode bug?

We also integrate external packages via Swift Package Manager which works perfectly fine. No issues there.

The issue is also well described in a post by Jesse Squires.

blackjacx
  • 9,011
  • 7
  • 45
  • 56

21 Answers21

168

Solution 1: File > Swift Packages > Reset Package Caches

enter image description here

Solution 2: File > Swift Packages > Update to Latest Package Versions

enter image description here

XpressGeek
  • 2,889
  • 3
  • 23
  • 27
64

For me, I needed File > Swift Packages > Reset Package Caches

Nicolas Degen
  • 1,522
  • 2
  • 15
  • 24
31

In Xcode go to File > Swift Packages > Update to Latest Package Versions

Worked for me

gexhange
  • 368
  • 2
  • 9
14

In Xcode go to Product > Clean Build Folder

This worked for me. The problem originally started when I was trying to solve another issue that came up after I deleted my Derived Data folder.

Restarting Xcode didn't work, but cleaning the build folder did. I don't know if the other answers here would work for me because I didn't try them seeing as cleaning the build folder worked.

LondonGuy
  • 10,778
  • 11
  • 79
  • 151
  • 1
    Even with a local package, I get the (misleading) error message whenever something is changed in the 'platforms' part of the package in Package.swift. This fixes it for me. – HendrikFrans Sep 11 '20 at 08:21
10

I bumped into this issue today on Xcode 13.0 when working on the WooCommerce iOS app after manually deleting the DerivedData folder.

The build was failing like in the questions description: Missing package product '<package name>'

screenshot of the build failure in Xcode

I tried both resetting the packages cache and updating to the latest versions, but neither work. Thinking about it, that's not surprising since the packages Xcode couldn't find were local packages.

What did the trick for me was following this suggestion from an Apple forums thread and remove the local packages references, then adding them back again.

In WooCommerce's case, the local packages are part of a workspace file. Removing then adding them back again in the same order didn't result in a diff in the file. That is, nothing really changed in the workspace setup, but that was apparently the kind of kick Xcode needed to get over that error. ‍♂️

mokagio
  • 16,391
  • 3
  • 51
  • 58
7

I'm not sure of the root cause, but I get this quite regularly. Not the most elegant solution, but neither Reset Package Caches nor Update to Latest Package Versions worked for me. For me, I had to quit Xcode, and delete DerivedData.

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

Then rebuild.

Matt Comi
  • 610
  • 6
  • 9
6

None of the answers worked for me on Xcode 12.5 beta. I had to manually remove all spm packages and re add them.

yzoldan
  • 188
  • 2
  • 14
  • Xcode 12.5 caches dependencies somewhere. This is new in this beta version. See https://stackoverflow.com/questions/66143815/xcode-12-5-spm-dependency-cache-location. If you find out where, it would help me a lot and also yourself since re-adding packages should not be necessary at all. You might just miss deleting the cache. – blackjacx Feb 12 '21 at 14:33
  • Thanks, mate! This answer saved me a lot of time! – oskarko Apr 28 '21 at 13:43
  • In Xcode 13, all the other offerings didn't help me. Deleting and re-adding a local package resolved the complaint. – bshirley Nov 26 '21 at 19:52
5

I tried:

  • Clean project
  • Clean derived data
  • Resolve Package Versions (File > Package)
  • Update to Latest Package Versions (File > Package)
  • Restart Xcode
  • Restart Mac

And restarting the Mac is what worked

Others say doing "Resolve Package Versions" multiple times also work.

Luis Ascorbe
  • 1,985
  • 1
  • 22
  • 36
4

SPM - Reset Package Caches vs Update to Latest Package Versions

File -> Swift Packages -> Reset Package Caches  
File -> Swift Packages -> Update to Latest Package Versions 

Update to Latest Package Versions

fetch the latest possible version(based on restrictions)

Reset Package Caches

reset cache(derived folder) -> Update to Latest Package Versions 

folder

<path_to_derived_data>/<randomizer>/SourcePackages/checkouts/<project_name>
//e.g
/Users/alex/Library/Developer/Xcode/DerivedData/SPM-dpsmlyjrashqjefkfheppizcrgic/SourcePackages/checkouts/SPMExperiments

[Local SPM]

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
3

I got this error when having the same local Swift package open in two different instances of Xcode in two different projects. Got it working again by quitting Xcode and only having one project open at a time.

Kent Robin
  • 2,066
  • 20
  • 19
2

A workaround for me at the moment has been both running Product > Clean Build Folder (cmd-k) and then restarting Xcode. This is an issue in both Xcode 12.4 and 12.5, and 12.5's per user package caching did not resolve the issue.

File > Swift Packages > Reset Package Caches also appears to work but it is slower for me.

Context:

One of my vendors distributes their pre-compiled binary library via SPM. Whenever I switch between git development branches, I get:

"artifact of binary target 'xyz' failed extraction: The operation couldn’t be completed. (TSCBasic.StringError error 1.)"

It also causes these "missing package product" errors for totally unrelated packages presumably because if one package fails the whole SPM process fails ("resolving package graph failed") even if these package are entirely independent.

Edit: With Xcode 12.5 simply quitting Xcode and re-opening seems to be enough.

slythfox
  • 545
  • 6
  • 12
2

Start with the other answers like

  • Reset Package Caches
  • Product > Clean Build Folder

If this doesn't help...

In my messages I found a hint that I had a dependency to two different version of the same package.

After fixing this, Reset Package Caches suddenly worked for most of my packages.

I could fix the remaining problems by adding

platforms: [
    .iOS(.v13),
],

to the corresponding package. Before that, I had no platforms statement.

Gerd Castan
  • 6,275
  • 3
  • 44
  • 89
1

Xcode Source Control should be enabled to run this. Preference -> Source Control and enable the source control.

1

If none of the above answers work, Please refer the solution shared by GravityBytes in this link on Apple Forums.

Eventually he happened to share the below resolution

I eventually got this resolved. What seemed to get it working was re-adding my local packages using the "Add Packages…" menu option on the project that has the framework targets using the local package. This created a new "Packages" group in the project, and eventually started compiling correctly.

Please remove the existing references and try adding them using the above approach.

Pradeep Reddy Kypa
  • 3,992
  • 7
  • 57
  • 75
1

Just a silly question: did you set up your git account on Xcode preferences?

enter image description here

Gastón Antonio Montes
  • 2,559
  • 2
  • 12
  • 15
1

Nothing worked for me except Product -> Clean Build Folder and Restart

Bogdan Razvan
  • 1,497
  • 1
  • 16
  • 16
1

For me, Xcode was opened using Rosetta which wans't enabled before. Disabling Rosetta helped me

Sercan Samet Savran
  • 755
  • 1
  • 9
  • 20
Ahmed M. Hassan
  • 709
  • 9
  • 14
1

I have a variation of this issue with 1 local library in 2 or more packages/projects. Just trick xcode into thinking that one local library is two or more:

  • Close all projects from menu bar or ctrl-option-cmd-w
  • Delete contents of ~/Library/Developer/Xcode/DerivedData
  • Delete any Package.resolved, .swiftpm or .build files in ALL packages that are local
  • Create a symbolic link to the local library "ln -s /pathToLib/MyLibrary /pathToLib/MyLibraryII"
  • Don't touch or open Package/Project A, Package/Project B has to change package to the path of MyLIbraryII. You can now open one library in two seperate
  • Rinse and repeat if necessary.
  • Just keep in mind, for future reference, that it's jury-rigged.
marc-medley
  • 8,931
  • 5
  • 60
  • 66
0

I had this issue after the current branch rename in the project and resolve it by clearing xcuserdata in workspace.

halfer
  • 19,824
  • 17
  • 99
  • 186
happycoder
  • 927
  • 3
  • 13
  • 28
0

For Moya I had to edit project file to Xcode heart's content

/* XCRemoteSwiftPackageReference "Moya" */ = {
                    isa = XCRemoteSwiftPackageReference;
                    repositoryURL = "https://github.com/Moya/Moya";
                    requirement = {
                            kind = upToNextMajorVersion;
                            minimumVersion = 13.0.2;
                    };

anything other than 13.0.2 results in unresolutio for the numerous semicircular dependencies that Moya package brings to the table.

This breathes a new life into https://foldoc.org/field+circus

Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66
-2

In Xcode 12.0.1 (12A7300) this bug has been fixed. It was auto-resolved by the Xcode update for me.

EDIT Xcode 12.5 [beta]

Apple added a SPM cache. See my question here. If you run into this problem with this Xcode version it might help to delete this cache.

blackjacx
  • 9,011
  • 7
  • 45
  • 56
  • 1
    Not fixed in my case. This solution https://stackoverflow.com/a/62498968/1358117 worked for me. – Hello world Oct 05 '20 at 00:46
  • Is it really not fixed for you?! I never had this issue again after Xcode 12 upgrade... Can somebody confirm this? – blackjacx Nov 09 '20 at 11:10
  • 1
    I'm not sure but seems like the link above is more likely a solution. – Hello world Nov 12 '20 at 01:49
  • The links solve it for the buggy Xcode version <12.0. Meanwhile the problem is gone wothout the need of intermediate fixes. This is why this one is my accepted answer. – blackjacx Jan 01 '21 at 16:29
  • updated the accepted answer, you're where right the answer to this question for Xcode 11 is actually not this one. But this answer is correct anyways so it shouldn't receive a downvote. – blackjacx Feb 24 '21 at 10:16
  • why you picked the new answer? its the same as i wrote a year ago... – Nicolas Degen Mar 10 '21 at 08:53
  • because it answers the question. especially since the question states Xcode 11.4 explicitly. so this answer is correct for this Xcode version. – blackjacx Mar 10 '21 at 14:12