Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift package: error: product dependency 'LineNoise' in package 'linenoise-swift' not found

I am using Swift package manager to manage dependencies in my project. I am trying to import LineNoise in my swift package, but I get this:

nathanfallet:SwiftMC nathanfallet$ swift run
Fetching https://github.com/andybest/linenoise-swift.git
Fetching https://github.com/Quick/Nimble.git
Fetching https://github.com/apple/swift-argument-parser
Fetching https://github.com/apple/swift-nio.git
Fetching https://github.com/adam-fowler/compress-nio.git
Cloning https://github.com/apple/swift-nio.git
Resolving https://github.com/apple/swift-nio.git at 2.17.0
Cloning https://github.com/adam-fowler/compress-nio.git
Resolving https://github.com/adam-fowler/compress-nio.git at 0.3.0
Cloning https://github.com/apple/swift-argument-parser
Resolving https://github.com/apple/swift-argument-parser at 0.0.6
Cloning https://github.com/andybest/linenoise-swift.git
Resolving https://github.com/andybest/linenoise-swift.git at 0.0.3
Cloning https://github.com/Quick/Nimble.git
Resolving https://github.com/Quick/Nimble.git at 7.3.4
'SwiftMC' /Users/nathanfallet/git/SwiftMC: error: product dependency 'LineNoise' in package 'linenoise-swift' not found

It is not the first package I import, and others are working (and I'm importing them the same way). I added the package to my Package.swift file like my other packages, but this one seems to be not working...

My Package.swift file:

// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "SwiftMC",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "SwiftMC",
            targets: ["SwiftMC"]),
        .executable(
            name: "SwiftMCRun",
            targets: ["SwiftMCRun"])
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
        .package(url: "https://github.com/adam-fowler/compress-nio.git", from: "0.0.1"),
        .package(url: "https://github.com/apple/swift-argument-parser", from: "0.0.1"),
        .package(url: "https://github.com/andybest/linenoise-swift.git", from: "0.0.1")
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "SwiftMC",
            dependencies: [
                .product(name: "NIO", package: "swift-nio"),
                .product(name: "CompressNIO", package: "compress-nio")
            ]),
        .target(
            name: "SwiftMCRun",
            dependencies: [
                "SwiftMC",
                .product(name: "ArgumentParser", package: "swift-argument-parser"),
                .product(name: "LineNoise", package: "linenoise-swift") // Error seems to come from here; I tried "linenoise", "LineNoise", "linenoise-swift" but nothing seems to work
            ]),
        .testTarget(
            name: "SwiftMCTests",
            dependencies: ["SwiftMC"]),
    ]
)

Any idea of what is wrong with it? Why is this package not importing while others are?

like image 204
Nathan Fallet Avatar asked May 16 '20 13:05

Nathan Fallet


1 Answers

Cause:

This issue happens when packages specify a different Package.name property compared to the github repo name. E.g. LineNoise's repo name is linenoise-swift but the Package.swift says is called LineNoise. You'll notice all your other dependencies have github repo name consistent with package.swift package name.

Fix: Just the package name to .package

To fix this, specify the package name of the package dependency explicitly in your Package.swift (you can find the name in the libraries package.swift file).

// Latest prerelease
.package(name: "LineNoise", url: "https://github.com/andybest/linenoise-swift", from: "0.0.3")

Now in your target dependency, you can use LineNoise as the package argument.

Another example (Mapbox Navigation):

I had a similar issue when using the MapBox Navigation library. Instead of using adding it like I add other libraries, the documentation stated to use a specific usage:

To install the MapboxNavigation framework in another package rather than an application, run swift package init to create a Package.swift, then add the following dependency:

// Latest prerelease
.package(name: "MapboxNavigation", url: "https://github.com/mapbox/mapbox-navigation-ios.git", .exact("2.0.0-beta.11"))

Anyway, it looks like your repo is not using lineNoise anymore 😅.

Note to package developers:

Make sure your GitHub repo is the same name as your package name, it will just be more convenient.

like image 126
Ben Butterworth Avatar answered Nov 14 '22 20:11

Ben Butterworth