Swift "Compiling for iOS ... but module was built for ..." arch mismatch in CI
The compiler is building for one platform/architecture but a dependency module was compiled for another. This happens when a cached or binary module does not match the current destination or a stale .build mixes platforms.
What this error means
Build fails with "error: Compiling for iOS X, but module 'Y' was built for iOS Z" or a "module compiled for a different architecture" variant.
error: Compiling for iOS 15.0, but module 'Networking' was built for iOS 17.0
error: could not build Objective-C module 'Networking'Common causes
A stale build directory mixes platforms
A .build or DerivedData directory restored from a different destination holds modules compiled for another deployment target or architecture.
A binary dependency built for a different target
A precompiled xcframework or binary target module was built for a platform/arch that does not match the current build.
How to fix it
Clean the build and rebuild for one destination
- Remove the stale
.build(and DerivedData if using Xcode). - Rebuild with a single, explicit destination or deployment target.
- Confirm all modules compile for the same platform.
rm -rf .build
swift buildMatch the deployment target across the graph
Set a consistent platform minimum so dependency modules and app code target the same iOS version.
platforms: [.iOS(.v15)],How to prevent it
- Key any build cache on the destination/platform so mismatched artifacts are not reused.
- Keep
platforms:consistent between the app and its packages. - Rebuild binary dependencies for every platform you ship.