Swift package: error: product dependency 'LineNoise' in package 'linenoise-swift' not found
Swift package: error: product dependency 'LineNoise' in package 'linenoise-swift' not found
我正在使用 Swift 包管理器来管理我项目中的依赖项。我试图在我的 swift 包中导入 LineNoise,但我得到了这个:
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
这不是我导入的第一个包,其他人正在工作(我正在以相同的方式导入它们)。我像其他包一样将包添加到我的 Package.swift
文件中,但是这个似乎不起作用...
我的 Package.swift
文件:
// 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"]),
]
)
知道它有什么问题吗?为什么这个包不导入而其他包导入?
原因:
当软件包指定与 github 存储库名称不同的 Package.name
属性 时,会发生此问题。例如。 LineNoise 的 repo 名称是 linenoise-swift
但 Package.swift
says is called LineNoise
。您会注意到所有其他依赖项的 github 回购名称与 package.swift 包名称一致。
修复:只将包名改为.package
要解决此问题,请在 Package.swift
中明确指定包依赖项的 包名称 (您可以在库 package.swift 文件中找到该名称).
// Latest prerelease
.package(name: "LineNoise", url: "https://github.com/andybest/linenoise-swift", from: "0.0.3")
现在在目标依赖项中,您可以使用 LineNoise
作为 package
参数。
另一个例子(Mapbox导航):
我在使用 MapBox Navigation 库时遇到了类似的问题。文档没有像我添加其他库那样使用添加它,而是使用 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"))
无论如何,您的 repo 似乎不再使用 lineNoise 了。
包开发人员注意事项:
确保你的 GitHub 仓库与你的包名同名,这样会更方便。
我正在使用 Swift 包管理器来管理我项目中的依赖项。我试图在我的 swift 包中导入 LineNoise,但我得到了这个:
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
这不是我导入的第一个包,其他人正在工作(我正在以相同的方式导入它们)。我像其他包一样将包添加到我的 Package.swift
文件中,但是这个似乎不起作用...
我的 Package.swift
文件:
// 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"]),
]
)
知道它有什么问题吗?为什么这个包不导入而其他包导入?
原因:
当软件包指定与 github 存储库名称不同的 Package.name
属性 时,会发生此问题。例如。 LineNoise 的 repo 名称是 linenoise-swift
但 Package.swift
says is called LineNoise
。您会注意到所有其他依赖项的 github 回购名称与 package.swift 包名称一致。
修复:只将包名改为.package
要解决此问题,请在 Package.swift
中明确指定包依赖项的 包名称 (您可以在库 package.swift 文件中找到该名称).
// Latest prerelease
.package(name: "LineNoise", url: "https://github.com/andybest/linenoise-swift", from: "0.0.3")
现在在目标依赖项中,您可以使用 LineNoise
作为 package
参数。
另一个例子(Mapbox导航):
我在使用 MapBox Navigation 库时遇到了类似的问题。文档没有像我添加其他库那样使用添加它,而是使用 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"))
无论如何,您的 repo 似乎不再使用 lineNoise 了。
包开发人员注意事项:
确保你的 GitHub 仓库与你的包名同名,这样会更方便。