Skip to content
Latchkey

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.

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

  1. Add the dependency product to the importing target's dependencies:.
  2. Confirm the product name matches what the package exports.
  3. Rebuild.
Package.swift
.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.

Terminal
swift package resolve
swift build

How to prevent it

  • List every imported product in the target's dependencies:.
  • Restore the .build/SourcePackages cache before building.
  • Run swift package resolve as an explicit early step in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →