skip to Main Content

I get "no such module" errors when trying to build after doing a "Clean Build Folder". Repeatedly trying to build eventually results in no errors.

IMPORTANT: The modules that can not be found are local packages with Swift Package Manager, i.e. not downloaded from git. I’m specifying these dependencies like this:

.package(url: "file:../CoreGraphicsExtensions", from: "0.0.0")

As seen in my /UIKitExtensions/Package.swift file listed here:

// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
        name: "UIKitExtensions",
        products: [
            // Products define the executables and libraries a package produces, and make them visible to other packages.
            .library(
                    name: "UIKitExtensions",
                    targets: ["UIKitExtensions"]),
        ],
        dependencies: [
            // Dependencies declare other packages that this package depends on.
            // .package(url: /* package url */, from: "1.0.0"),
            .package(url: "file:../CoreGraphicsExtensions", from: "0.0.0")
        ],
        targets: [
            // Targets are the basic building blocks of a package. A target can define a module or a test suite.
            // Targets can depend on other targets in this package, and on products in packages this package depends on.
            .target(
                    name: "UIKitExtensions",
                    dependencies: []),
            .testTarget(
                    name: "UIKitExtensionsTests",
                    dependencies: ["UIKitExtensions"]),
        ]
)

Here is what I see in Xcode when I am trying to build.

First build…

enter image description here

Second Build…

enter image description here

Third Build…

enter image description here

Fourth Build…

enter image description here

Fifth Build…

enter image description here

… finally it runs. 🥳

But there are some strange warnings about the packages not being used by any target.

enter image description here

How can I get this to build correctly first time after a clean build?


My workspace structure looks like this…

enter image description here

Two projects in the workspace. BlenderViewer has the target I’m building. BlenderViewer has 6 local SPM packages. It also imports the PhyKit project as a framework, no problems there. The SPM packages have some dependencies between each other, but nothing circular.

Everything looks fine to me…

enter image description here

enter image description here

I’m running MacOS 12.5. Xcode 13.4.1. Building for iOS 15.3.

Am I doing something wrong here?

4

Answers


  1. When you removed derived data or sometimes Xcode’s package cache gets confused. This will usually result in weird build errors that can’t really be explained. Here is things that might help:

    Resetting the Xcode Package Cache: To reset the package cache, open the File menu, navigate to Packages, and click Reset Package Caches. This will delete all local package data and redownload each package from its source online. Wait till all the packages downloads

    Login or Signup to reply.
  2. You can try Xcode CommandLine tool instead:

    xcodebuild on the project directory

    It usually works without this frustrating issue

    Login or Signup to reply.
  3. I had the same error with an online package (after removing and re-adding it), and also had no luck with the other suggestions to clean derived data, reset package cache, and resolve dependencies from the command line.

    What I found eventually, was that the package in question needed to be manually re-added to the app target in Build Phases > Link Binary with Libraries. This solved the issue.

    Login or Signup to reply.
  4. I had the same with TestTarget which can’t resolve the main target local SPM
    finally, fix with this approach
    I added all main target dependencies to the test target too and after that find, I had some compiler issues in which the compiler showed me this wrong error, and when errors were fixed this error disappeared

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search