PC パソコン

How to Fix Xcode ‘Module cache file not found’

When Xcode shows a “Module cache file not found” error, the build usually fails because Xcode or Clang is pointing to a cached module file that no longer exists. This commonly happens after an Xcode update, an SDK change, a partial cleanup of DerivedData, dependency changes, or reuse of stale caches in CI.

What the error means

A typical message looks like this:

error: module cache file '/path/to/ModuleCache/...pcm' not found

Xcode creates module cache files to speed up compilation of Swift and Objective-C code. If the cache was removed, corrupted, or created by a different Xcode or SDK version, the compiler may still try to reference a file that is no longer valid.

Common situations where it appears

  • Immediately after updating Xcode
  • After updating macOS or an Apple SDK
  • After deleting only part of DerivedData
  • After switching branches with major build-setting changes
  • After updating CocoaPods or Swift Package Manager dependencies
  • When a CI system restores an old ModuleCache or DerivedData archive
  • When switching between multiple Xcode versions

What to check first

In Xcode’s Issue Navigator, inspect the path shown immediately before the error. In many cases it points to DerivedData or ModuleCache.noindex.

~/Library/Developer/Xcode/DerivedData/.../ModuleCache.noindex/

Also verify which Xcode installation is active:

xcode-select -p
xcodebuild -version

If you have more than one Xcode installed, confirm that the selected developer directory matches the Xcode version you intend to use.

Fix 1: Clean the build folder

In Xcode, choose Product → Clean Build Folder, then build again. This removes more generated build artifacts than a normal clean and is often enough when the cache mismatch is minor.

If Clean Build Folder is not visible, hold the Option key while opening the Product menu.

Fix 2: Delete DerivedData

The most reliable fix is to remove the affected project’s DerivedData and let Xcode regenerate it. Open Xcode Settings → Locations → Derived Data, open the folder, and delete the folder for the affected project.

To remove all DerivedData from Terminal:

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

The next build may take longer because Xcode must rebuild indexes, module caches, and dependencies.

Fix 3: Remove only ModuleCache

If you do not want to delete all DerivedData, remove the module cache and let Xcode recreate it:

rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache.noindex

Depending on the environment, ModuleCache may also exist inside a project-specific DerivedData directory. Use the path from the error message to identify the correct cache location.

Fix 4: Quit Xcode before deleting caches

If Xcode is still running while cache files are removed, stale references may remain in memory. Quit Xcode completely, delete DerivedData or ModuleCache, and then reopen Xcode.

Fix 5: Check the selected Command Line Tools

If the problem started after switching Xcode versions, xcode-select may still point to a different installation.

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Adjust the path if your Xcode app is installed elsewhere, then verify it:

xcode-select -p
xcodebuild -version

Fix 6: If you use CocoaPods

If the error started after changing Pods, clear DerivedData and reinstall dependencies:

pod deintegrate
pod install

After reinstalling, open the .xcworkspace file rather than the .xcodeproj file.

Fix 7: If you use Swift Package Manager

If the issue appeared after package changes, reset package caches from Xcode’s File → Packages menu and resolve dependencies again. Deleting DerivedData as well can help if the stale module cache is still being reused.

If it happens in CI

Do not reuse the same DerivedData or ModuleCache across different Xcode or SDK versions. Include values such as the Xcode version, SDK version, and dependency lock files in your cache key.

xcodebuild -version
xcrun --sdk iphoneos --show-sdk-version

In many CI setups, excluding ModuleCache from persistent cache storage improves reliability.

If the error still does not go away

  1. Quit Xcode
  2. Delete DerivedData
  3. Restart the Mac
  4. Restore project dependencies
  5. Verify the xcode-select path
  6. Test whether a brand-new Xcode project builds successfully

If a new project shows the same error, the issue is more likely related to the Xcode installation or Command Line Tools than to the original project.

Important note

Do not try to manually create or copy the missing .pcm file shown in the error. Module cache files are generated by Xcode and Clang for the active toolchain and SDK, so clearing the stale cache and letting Xcode rebuild it is safer.

Summary

“Module cache file not found” is usually caused by a mismatch between Xcode’s current build environment and an old or missing module cache. Start with Clean Build Folder, then remove DerivedData or ModuleCache if necessary. When multiple Xcode versions are installed, verify the xcode-select path. For CocoaPods, Swift Package Manager, and CI environments, also make sure stale dependency or build caches are not being restored.