BS
BleepingSwift
Published on

> Fixing "No Such Module" Errors in Xcode

Authors
  • avatar
    Name
    Mick MacCallum
    Twitter
    @0x7fs

You've added a dependency via Swift Package Manager or CocoaPods, the installation completed successfully, and yet Xcode shows a red error: "No such module 'SomeLibrary'". The module exists. You can see it in your project navigator. But Xcode insists it doesn't. This disconnect is one of the most common—and most frustrating—Xcode issues, but it's almost always fixable once you know where to look.

Build First, Then Worry

Before diving into diagnostics, try building your project (⌘B). Some dependencies don't appear available until they've been built at least once. If the error disappears after building, you're done. This is especially common with Swift Package Manager dependencies.

If the error persists after building, keep reading.

Swift Package Manager Dependencies

SPM dependencies live in your project's package resolution system. When they can't be found, check these things:

Verify the package resolved correctly. Open File → Packages → Resolve Package Versions. Watch for errors in the activity window. If resolution fails, you'll see why.

Check the package is linked to your target. Select your project in the navigator, choose your target, go to "Frameworks, Libraries, and Embedded Content" under the General tab. Your dependency should be listed there. If it's not, click the plus button and add it.

Try resetting the package cache. Go to File → Packages → Reset Package Caches. This clears downloaded packages and re-fetches them, fixing corruption issues.

Delete the Package.resolved file. In Finder, navigate to your project's .xcodeproj folder (or .xcworkspace for workspaces) and delete the Package.resolved file inside. Reopen the project and let Xcode resolve packages fresh.

CocoaPods Dependencies

CocoaPods has its own set of quirks. The most common cause of "No such module" with CocoaPods is forgetting to open the workspace file.

Open the .xcworkspace, not .xcodeproj. After running pod install, CocoaPods creates a workspace that includes both your project and the Pods project. If you open the .xcodeproj directly, your code can't see the pods.

Run pod install again. Dependencies might be out of sync:

cd /path/to/your/project
pod install

If that doesn't help, try deintegrating and reinstalling:

pod deintegrate
pod install

Check your Podfile's target. Make sure the pod is included in the correct target:

target 'YourAppName' do
  use_frameworks!
  pod 'Alamofire'
end

If you have multiple targets (like an app and an extension), each target needs its dependencies listed explicitly or inherited with inherit! :search_paths.

Architecture Mismatches

On Apple Silicon Macs, architecture mismatches cause many "No such module" errors. The module might build for arm64 but your target needs x86_64 (for the simulator), or vice versa.

Check your build destination. The device selected in Xcode's toolbar affects which architectures get built. Try switching between a simulator and a real device to see if the error changes.

Ensure your dependency supports the architecture. Some older binary frameworks don't include arm64 simulator slices. Check the dependency's documentation or GitHub issues for Apple Silicon compatibility notes.

For binary dependencies, you might need to set "Build Active Architecture Only" to No in your build settings for Debug builds to ensure all required architectures are built.

Import Statement Issues

Sometimes the error is simpler than you'd expect.

Check the module name. The import name isn't always the same as the package or pod name. For example, the Firebase iOS SDK pod Firebase/Auth is imported as FirebaseAuth, not Firebase/Auth. Check the library's documentation for the correct import.

Case sensitivity matters. import alamofire won't work if the module is Alamofire. Swift imports are case-sensitive.

Check for typos. It sounds obvious, but double-check your spelling. A missing letter is easy to overlook when you're convinced the module should exist.

Build Settings Problems

Misconfigured build settings can hide otherwise-valid modules.

Check Framework Search Paths. In your target's Build Settings, search for "Framework Search Paths." If you've manually added paths that are incorrect or missing, frameworks won't be found. For SPM dependencies, you generally shouldn't need to modify this. For CocoaPods, the Pods project should set this automatically.

Check the Import Paths setting. Search for "Import Paths" in Build Settings. This is where Swift looks for modules. Usually you don't need to modify this, but if it's been changed, it might be pointing somewhere wrong.

Ensure "Find Implicit Dependencies" is enabled. In your scheme's Build settings (⌘< then edit scheme), make sure "Find Implicit Dependencies" is checked. This lets Xcode discover dependencies automatically.

Clean and Rebuild

When configuration looks correct but the error persists, stale build products may be the culprit.

Clean the build folder. Press ⇧⌘K or go to Product → Clean Build Folder.

Delete DerivedData. Close Xcode, then:

rm -rf ~/Library/Developer/Xcode/DerivedData

Reopen your project and build. This forces Xcode to rebuild everything including dependencies.

Test Targets and Extensions

If the error appears only in a test target or app extension, the dependency might not be linked to that target.

For Swift Package Manager, select your project, choose the test target, and add the dependency under "Frameworks, Libraries, and Embedded Content."

For CocoaPods, ensure your Podfile includes the pod in the correct target, or use inherit! to share pods between targets:

target 'YourApp' do
  use_frameworks!
  pod 'Alamofire'

  target 'YourAppTests' do
    inherit! :search_paths
  end
end

When All Else Fails

If you've tried everything and the module still can't be found, try these last-resort steps:

  1. Quit Xcode completely
  2. Delete DerivedData
  3. Delete the Pods folder and Podfile.lock (if using CocoaPods)
  4. Delete .swiftpm folder (if using SPM)
  5. Delete Package.resolved
  6. Restart your Mac
  7. Open Terminal, navigate to your project, run pod install (if using CocoaPods)
  8. Open the workspace in Xcode
  9. Let Xcode resolve packages
  10. Build

This resets nearly everything and usually resolves even the most stubborn issues. The problem was almost certainly corrupted cached data somewhere in the chain, and starting fresh eliminates it.

subscribe.sh

// Stay Updated

Get notified when I publish new tutorials on Swift, SwiftUI, and iOS development. No spam, unsubscribe anytime.

>

By subscribing, you agree to our Privacy Policy.