"Missing package product" error for all local Swift Packages when switching git branches

I'm seeing a consistent Xcode error for all of my local swift packages when switching git branches or doing a git pull while Xcode is open.

A workaround that works ~75% of the time:

  1. Kill xcode
  2. Then completely remove the derived data directory (empty trash just to be absolutely sure).
  3. Restart Xcode
  4. Reset Swift package cache

On some occasions, this workaround fails and am forced to do a fresh git clone. Has anyone else seen this before?
Xcode Version 11.5 (11E608c)
swift-tools-version:5.2

5 Likes

What are the errors in your package resolution log? You can find that in the report navigator under the project/workspace node.

@NeoNacho The Package resolution log shows no errors. Looks like it only applies to remote swift packages. Here is the export of the log. The error above is specifically for local packages only.
Package Resolution log:

Showing All Messages   
Resolve Package Graph
Activity Log Complete    6/30/20, 11:26 AM    7.5 seconds

Build log:

Showing All Messages

Prepare build
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description

Build target <target name> of project <project name> with configuration Debug
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
error: Missing package product '<local package name>' (in target '<target name>' from project '<project name>')
Build failed    6/30/20, 11:19 AM    1.2 seconds

I'm slightly confused by these logs, for two reasons:

  • According to the time stamps, the resolution log is newer than the build log, but resolution has to happen before the build. Could you check if there are any errors in previous logs?

  • It looks like this is a different case than the initially reported one, this log is missing the extra "Package resolution errors must be fixed before building" the previous one had. This could potentially be an issue with the log export that I am not aware of though.

@NeoNacho I created a sample app which demonstrates this. It contains a dynamic framework linking into a app target. Two remote swift packages and one local swift package statically link into the framework.

I built master, then git checkout Test -- on command line, tried to build and failed instantly, all while Xcode is open.

This feels more like an Xcode bug rather than a Swift Package Manager issue. I filed a radar: FB7831146

1 Like

same issue here

I get this same kind of problem with Cocoapods and Xcode when switching branches. I may have different versions of specific pods in the different branches. I pod install after switching the branch but Xcode doesn't seem to notice that the dependencies have changed so doesn't build them. I get link errors for methods that are in one version of a pod but not in another so I can tell it didn't build the dependency.

This all started for me with the new build system. You might try to see if the legacy build system works better.

Usually Clean Build Folder works to fix this for me.

Our team is also experiencing this - we use both Cocoapods (for now) and SPM and our local packages do this every time we switch branches. What works for me is closing the workspace before switching branches... which is annoying to say the least. Is there anything we can do to help get this fixed?

Package resolution log:

Showing All Messages
Resolve Package Graph


Activity Log Complete    05/08/2020, 10:31    0.6 seconds

Build log:


Showing All Messages

Prepare build
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Using build description from memory



Build target <name> of project <name> with configuration Debug
error: Missing package product 'Deeplinks' (in target '<name>' from project '<name>')
error: Missing package product 'LocationProvider' (in target '<name>' from project '<name>')
error: Missing package product 'CountryCodes' (in target '<name>' from project '<name>')
error: Missing package product 'ReachabilityInternetProvider' (in target '<name>' from project '<name>')
error: Missing package product 'LanguageCodes' (in target '<name>' from project '<name>')
error: Missing package product 'BaggageDistributor' (in target '<name>' from project '<name>')
error: Missing package product 'ReachabilityInternetProvider' (in target '<name>' from project '<name>')




Build failed    05/08/2020, 10:31    0.2 seconds

This is on Xcode 11.6.

1 Like

We are aware of this and are investigating.

2 Likes

Update: Got a reply from my Apple Radar FB7831146 to retest against Xcode 12 Beta 5. Issue still exists.

Sorry, seems like there was a mistake somewhere. There is no fix for this in Beta 5 and you shouldn't have been asked to verify.

This seems to be fixed in Xcode 12(.0.1?) for us :tada:

The fix landed in the Xcode 12 GM.

1 Like

Thanks @NeoNacho for nudging this along! Discovered a new SPM bug I think and started a new thread here: Xcode fails to resolve locked Package.resolved file when switching git branches while Xcode app is open - #2 by ray

In Xcode 12.5, I get the "missing package product" error message when two of my own Swift packages in the workspace have the same third-party package dependency, with the same version(!). Making only one of my packages use the third-party Swift package solves the problem.

I've been building just fine with a dozen SPM dependencies, and am now running into this. I had a merge conflict with Package.resolved (not sure why it keeps changing). I discarded it, and ran into the problem. I told Xcode 13b1 to Resolve Package Versions, but that didn't seem to do anything. So I reset the cache, and that seemed like it was working, but when it was all done, there was still one missing package. There are no errors in the resolution log. The one missing package is not in the Package.resolved file.

I just tried deleting the resolved file again. Xcode re-creates it, but it's always missing that one package, despite it being in the project list of dependencies.

I just tried removing it and re-adding it to the Xcode project. Didn't fix the resolved file, same error.

I reset it again. Now I see it's kinda skipping Marshal, and I realize it's because it's supposed to be finding my checked-out version of the package that I modified. So I poked around my project for a bit to see if it was still there, and it was. I built again, and it worked.

I have no idea what was going on, but this wasn't good.

It also brings up a question: what happens if I've taken the steps to make an SPM dependency editable in Xcode, and I commit and a colleague pulls but doesn't have the same writable package?

In Xcode 13 RC, if I download Ray's sample project and then try and build it after the packages resolve I see Missing package product 'Performance'

I also see it in my real life project. Is anyone else seeing these issues in Xcode 13?

My colleagues noticed it occur occasionally in Xcode 12.5.1 and Xcode 13 RC. Solution so far is to restart Xcode. @NeoNacho ^

1 Like

I just tried Xcode 13 GM and tried to build my project because I previously had the same issues in Xcode 12.5.1. My solution in Xcode 12.5.1 was always those two things

  • reset package caches
  • restart Xcode

I am unable to build my project with Xcode 13 GM even after doing these steps. I even tried:

  • restarting my Mac
  • removing derived data

Unfortunately with no success and at the moment I am unable to build my project in Xcode 13 GM at all.

Ah, and when I reset package cache Xcode 13 GM is consistently crashing.

2 Likes

My work project was crashing or not responding all the time when using Xcode 13. I fixed it partially and now it’s not crashing anymore, but it’s now consistently not responding after resolving packages.
Other projects are fine, but the one I get paid for is not :clown_face:

But there is one side project that I cannot build using Xcode 12 due to "Missing package product error", whatever I do (restarting Xcode/Mac, resetting package caches/resolving or updating packages/clearing derived data), but it builds just fine with Xcode 13 or with Xcode 12 swift build from the command line :new_moon_with_face:

1 Like