How do I fix 'No such module 'XYZ' after adding a package' in Xcode/Swift?

If you encounter the error 'No such module 'XYZ'' after adding a package in Xcode/Swift, it indicates that Xcode is unable to find the module you've integrated into your project. This issue can often arise due to various reasons such as issues with package installation, incorrect import statements, or project configuration problems.

Common Solutions

  • Make sure your package was added correctly by checking your project's Package Dependencies.
  • Perform a clean build. Select Product > Clean Build Folder from the Xcode menu (or use the shortcut Shift + Command + K).
  • Ensure that you have the correct target selected for your project. Packages added may not be available to all targets.
  • Check that you have included the package in the Link Binary With Libraries section of your target's build phases.

Example of Importing a Module

import XYZ // Replace 'XYZ' with your module name
    // Use the module here
    

By following the above steps, you should be able to resolve the 'No such module 'XYZ'' error and successfully import and utilize your package in Xcode.


No such module Xcode Swift package module not found import error Xcode troubleshooting