Swift "no such module 'X'" for an SPM dependency in CI
The compiler tried to import X but no module named X was built or found. With SwiftPM this usually means the dependency was not resolved, not declared as a target dependency, or the build ran before packages were fetched.
What this error means
Compilation fails with "error: no such module 'X'" at the import line, even though the package is listed in Package.swift.
Sources/App/Client.swift:1:8: error: no such module 'Networking'
import Networking
^Common causes
The dependency is not a declared target dependency
The package is in .package(...) but the importing target does not list the product in its dependencies:, so the module is not on the compile path.
Packages were not resolved or restored before build
A cache miss or a skipped resolve step means the module was never built, so the import cannot find it.
How to fix it
Declare the product as a target dependency
- Add the dependency product to the importing target's
dependencies:. - Confirm the product name matches what the package exports.
- Rebuild.
.target(
name: "App",
dependencies: [
.product(name: "Networking", package: "networking")
]
)Resolve packages before building
Ensure a resolve step runs (and any SwiftPM cache is restored) so the module is built before compilation.
swift package resolve
swift buildHow to prevent it
- List every imported product in the target's
dependencies:. - Restore the
.build/SourcePackages cache before building. - Run
swift package resolveas an explicit early step in CI.