Could not find module 'MyPackage' for target 'x86_64-apple-macos'; found: arm64, arm64-apple-macos

Hardward: Mac mini M1
OS: macOS 12.1
Xcode: 13.2.1

SPM
Swift Package name: MyPackage

Application
macOS Application name: MyPackageTest(include MyPackage)
macOS Application Architectures: Apple Silicon, Intel

Encountered Swift compiler error: Could not find module 'MyPackage' for target 'x86_64-apple-macos'; found: arm64, arm64-apple-macos

How do i resolve this error when I build macOS application MyPackageTest?

1 Like

I had a similar error in my project (also running Xcode 13.2.1 on an M1 mini), but only in the unit test target associated with my program (a command line tool rather than an application). Oddly, the error pointed to the @testable import <program_name> line in one of my unit test source files, and only when the selected scheme was the one for the unit test target.

Searching the Internet for the text of the error message led me to a Developer Forum post that suggested editing the Architecture setting (under Build Settings) and replace the default value of "$(ARCHS_STANDARD)" (displayed as "Standard Architectures (Apple Silicon, Intel)") with the explicit values "arm64" and "x86_64". I tried this and it seemed to work for me.

However, in subsequent experimentation I found that it appeared to be sufficient (in my case, anyway) to ensure that the Architecture was set to "$(ARCHS_STANDARD)" directly on the project, instead of inheriting the value from the "macOS Default". So your mileage may vary.

In any case, I hope this helps.

In my case, I have added test target to the project after the pod init, install etc..
And I saw, adding test target block in podfile solved my problem.

target 'SampleProject' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for SampleProject

  target 'SampleProjectTests' do
    inherit! :search_paths
    # Pods for testing
  end
end