6

我在做教程时遇到了这个错误。我无法解决问题。因此,我删除了该项目并创建了一个新的简单项目来解决问题,但仍然遇到同样的问题。我正在发布相关代码 -

package.swift 代码 -

// swift-tools-version:4.0
import PackageDescription

let package = Package(
name: "dep",
products: [
    .library(name: "dep", targets: ["App"]),
],
dependencies: [
    //  A server-side Swift web framework.
    .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),

    //  Swift ORM (queries, models, relations, etc) built on SQLite      3.
    .package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0"),
        .package(url: "https://github.com/vapor/leaf.git", from: "3.0.0"),

],
targets: [
    .target(name: "App", dependencies: ["Leaf","FluentSQLite", "Vapor"]),
    .target(name: "Run", dependencies: ["App"]),
    .testTarget(name: "AppTests", dependencies: ["App"])
]

)

当我在终端中执行“vapor build”并按 Enter 时,终端显示错误 - “”/Users/apple/dep: error: package at \'/Users/apple/dep\' is using Swift tools version 3.1.0 which不再支持;改用 4.0.0 或更新版本\n",输出:"")"

我已经完成了通常的工作,例如清理构建文件夹、清理派生数据等。现在,我接下来应该做什么。如果您需要更多信息,我可以发布代码或屏幕截图。

4

3 回答 3

6

一个有点详细的清单是……</p>

  1. 检查 Swift 版本。然后,如果需要,为 macOS 上最近发布的 Swift 版本更新 Xcode。在 Xcode > Preferences > Locations > Command Line Tools 中,确认Command Line Tools:指向当前工具链版本。Xcode 11.3 (11C29) 提供 Swift 5.1。
swift --version
# Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
# Target: x86_64-apple-darwin18.7.0
  1. 如果需要,更新并升级brew到最新版本。(或者,如果尚未安装 Homebrew 包管理器,请参阅https://brew.sh/ 。)
brew --version
# Homebrew 2.2.2
# Homebrew/homebrew-core (git revision dc049; last commit 2019-12-28)

brew update
brew upgrade # Note: upgrade all brew installed formulas.
#brew upgrade FORMULA # use only update one formula
  1. 检查vapor/tap水龙头。或者,可以移除并重新安装水龙头。
brew tap  # list existing taps
# homebrew/core
# vapor/tap

brew untap vapor/tap
# Untapping vapor/tap...
# Untapped 7 formulae (148 files, 69.8KB).

brew tap --full vapor/tap
  1. 现在,有了先决条件,安装(或重新安装)Vapor 3 vaporvia brew. Vapor 4 betavapor-beta有一个github 问题
# if vapor has not been installed, then `install`
brew install vapor            # Vapor 3
brew install vapor/tap/vapor  # same as above. path specified formula.
#brew install vapor-beta # Vapor 4 Beta

# if vapor is already installed, the `reinstall`
brew reinstall vapor
  1. 核实。
swift --version
# Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
# Target: x86_64-apple-darwin18.7.0

vapor --version
# Vapor Toolbox: 3.1.10 .... wait, what?

brew info vapor
# vapor/tap/vapor: stable 3.1.12
# https://vapor.codes
# /usr/local/Cellar/vapor/3.1.12 (6 files, 17.8MB) *
#  Built from source on 2019-12-28 at 12:46:27
# From: https://github.com/vapor/homebrew-tap/blob/master/vapor.rb

# try 
vapor new SomeProjectName --template=api # or, --template=web
cd SomeProjectName
vapor build
# No .build folder, fetch may take a while...
# Fetching Dependencies [Done]
# Building Project [Done]

哦,Vapor Toolbox 3.1.12 声称是“3.1.10”。请参阅 GitHub 问题https://github.com/vapor/toolbox/issues/292

  1. 生成 Xcode 项目
# still in SomeProjectName terminal working directory
vapor xcode
于 2019-12-28T21:19:17.763 回答
6

除了 l-marc-l 发布的答案之外,我必须尝试的第一步是删除 "// swift-tools-version:4.0" 行上方的空行,即 package.swift 中的第一行,它可以轻松解决了我的问题。如果那样不能解决问题,那么我会采取 l --marc l 提到的步骤。

于 2020-01-10T15:05:20.973 回答
0

您要么需要更新工具箱 ( brew upgrade vapor) 要么只运行swift build

于 2019-12-28T15:54:09.913 回答