'"Missing required module 'XYZ'" on Unit Tests when using Swift Package Manager
I'm using Swift Package Manager on an iOS app on Xcode 11 following the instructions from https://developer.apple.com/videos/play/wwdc2019/408/
Everything looks great, except Unit Tests won't work now.
Solution 1:[1]
After researching a bit, I got this fixed by adding -Xcc -fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps/macosx/<missing module name>.modulemap to OTHER_SWIFT_FLAGS in the test target.
Source:
- https://github.com/apple/swift-nio/issues/1128#issuecomment-527566361
- https://github.com/ReactiveX/RxSwift/issues/2057#issuecomment-538371425
- https://github.com/swift-aws/aws-sdk-swift/issues/167#issuecomment-527650662
PS: Use -Xcc -fmodule-map-file=$(PROJECT_TEMP_ROOT)/GeneratedModuleMaps/iphonesimulator/<module name>.modulemap if your platform is iOS.
UPDATE: Also, it seems that this is fixed on Xcode 11.2 beta2
Solution 2:[2]
This occurs because at the moment (Xcode 11.1, October 2019) SPM decencies are not automatically linked to test targets.
We can manually link it by:
- Clicking on your Xcode project file (e.g.
Headlines) - Select test target from the sidebar (e.g.
HeadlinesTests) - Navigating to
Build Phasesin the top bar. - In the
Link Binary With Librariesphase, add the required library from the SPM dependency (this looks like a white building within the SPM package ?). - You may also need to add the library to the
Dependenciesphase.
Solution 3:[3]
I saw this in Xcode 13 after I created a multi-platform app & had checked the box to create tests. The issue seems to be that Xcode created UI tests rather than unit tests as I had expected. I just made a new unit test target and everything worked as expected when importing my app in the test file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Bradley Mackey |
| Solution 3 | Trev14 |



