Error for missing module, but its listed in Package.swift

I am starting Swift learning on my new project (coming from python). Trying to implement SwiftArgs I get a missing dependency error

Package.swift

dependencies: [ .package(url: "https://github.com/pkrll/SwiftArgs", from: "0.5.0") ],

Source

But in main.swift the includ portion fails:

import SwiftArgs

Building for debugging...
warning: Will not do cross-module incremental builds, priors saved at TimePoint(seconds: 1688730938, nanoseconds: 0)), but the previous build started at TimePoint(seconds: 1688730938, nanoseconds: 817756000), at '/home/ronaldo/Projects/slife/.build/x86_64-unknown-linux-gnu/debug/slife.build/master.priors'
error: emit-module command failed with exit code 1 (use -v to see invocation)
/home/ronaldo/Projects/slife/Sources/main.swift:20:8: error: no such module 'SwiftArgs'
import SwiftArgs
       ^
/home/ronaldo/Projects/slife/Sources/main.swift:20:8: error: no such module 'SwiftArgs'
import SwiftArgs

Not sure how I can remediate this. Why does it repeat the error? Thanks for any help or guidance.

Hi there!

In Package.swift, you have added a dependency to the package. After doing that, you should also add a dependency (to one or more of your targets) to a product from the package you've just added.

Here is an example manifest:

// swift-tools-version: 5.9

import PackageDescription

let package = Package(
  name: "package_name",
  products: [
    .library(
      name: "library_name",
      targets: ["target_name"]
    )
  ],
  dependencies: [
    .package(url: "https://github.com/pkrll/SwiftArgs", from: "0.0.1")
  ],
  targets: [
    .target(
      name: "target_name",
      dependencies: [
        "SwiftArgs"
      ]
    )
  ]
)

In this example, we specify that the product SwiftArgs from the package SwiftArgs should be a dependency for the target target_name. Make sure that the version of the package matches the one you want to use.

If you want to learn more about the Swift Package Manager, I strongly recommend checking out the official documentation: Swift.org - Package Manager

1 Like

Maybe you forget to add SwiftArgs in your target's dependency.

Example Package.swift file

let package = Package(
    name: "DemoKit",
    products: [
        .library(name: "DemoKit", targets: ["DemoKit"]),
    ],
    dependencies: [
        .package(url: "https://github.com/pkrll/SwiftArgs", from: "0.5.0"),
    ],
    targets: [
        .target(
            name: "DemoKit",
            dependencies: [
                // I guess you probably missed this line of code.
                .product(name: "SwiftArgs", package: "SwiftArgs"),
            ]
        ),
        .testTarget(
            name: "DemoKitTests",
            dependencies: ["DemoKit"]),
    ]
)
1 Like

Indeed thats what the issue was.