Xcode stores build intermediates, indexes, module caches, and other generated data in DerivedData. When those files become stale or corrupted, a project can fail to build even when the source code itself is correct. This guide explains how to identify DerivedData-related problems and fix them safely.
Common causes
- Old build cache remaining after an Xcode or SDK update
- Inconsistent intermediates after switching Git branches or updating dependencies
- Corrupted ModuleCache or index data
- The same project being opened with different Xcode versions
- Changes to Swift Package Manager, CocoaPods, or build settings not reflected in cached files
Typical situations
DerivedData is especially worth checking when a project built correctly before, suddenly starts failing, and the reported error does not match the current source code.
- Clean Build Folder does not fix the issue
- Errors such as No such module, Could not build module, or Module cache file not found appear
- The same code builds on another Mac or in CI
- Code completion or symbol navigation behaves incorrectly
- The problem starts immediately after dependency or branch changes
How to check
- Open the Issue Navigator and identify the first real build error.
- Check whether the failure appeared without a relevant source-code change.
- Review recent changes to Xcode, the SDK, Swift Packages, CocoaPods, or Git branches.
- Run Product > Clean Build Folder and rebuild.
- If the issue remains, remove DerivedData and let Xcode regenerate it.
Fix 1: Delete DerivedData from Xcode
Open Xcode Settings or Preferences, go to Locations, and use the folder button next to Derived Data to open it in Finder. Delete the folder for the affected project, restart Xcode, and build again.
Deleting DerivedData does not delete your source code or project files. Xcode recreates the required generated files during the next build.
Fix 2: Delete DerivedData from Terminal
To remove all DerivedData, quit Xcode first and run:
rm -rf ~/Library/Developer/Xcode/DerivedData/*
Then reopen Xcode and rebuild the project.
Fix 3: Run Clean Build Folder
Before deleting all cached data, try Product > Clean Build Folder. The standard shortcut is:
Shift + Command + K
This can clear stale build products without removing every item in DerivedData.
Fix 4: Re-resolve Swift Package dependencies
If the project uses Swift Package Manager, use the Package menu to reset package caches or resolve package versions again. You can also re-resolve dependencies from the command line:
xcodebuild -resolvePackageDependencies -project YourProject.xcodeproj
If you build from a workspace, specify the appropriate -workspace and -scheme options instead.
Fix 5: Reinstall CocoaPods dependencies when needed
For CocoaPods projects, the problem may involve the Pods installation as well as DerivedData. Check that Podfile.lock is consistent, then run:
pod install
Use pod update only when you intentionally want to update dependency versions.
Fix 6: Fully restart Xcode
Xcode can continue holding index or module state in memory after cache changes. Quit Xcode completely, reopen the project, and rebuild after deleting DerivedData.
Important notes
DerivedData deletion is a troubleshooting step, not a permanent fix for every build problem. If the project only builds after repeatedly deleting DerivedData, inspect build settings, dependency configuration, Header Search Paths, Framework Search Paths, Swift Packages, CocoaPods, and custom build scripts for the underlying cause.
The first build after deleting DerivedData is usually slower because Xcode must regenerate indexes and intermediate files. In CI, also review cache keys and the Xcode version used by the build environment.
Summary
When Xcode suddenly reports unexplained build or module errors, stale or corrupted DerivedData may be responsible. Start with Clean Build Folder, then remove the affected DerivedData if necessary. If the project uses Swift Package Manager or CocoaPods, re-resolve those dependencies as well. If the same failure keeps returning, investigate the project configuration or dependency setup instead of repeatedly clearing the cache.
