7

I had this error when I was doing a tutorial. I could not solve the problem. So, I deleted the project and made a new simple project to figure-out the issue,but still having the same issue. I am posting relevant code -

package.swift code -

// 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"])
]

)

When I do "vapor build" in terminal and press enter, the terminal shows error - " "/Users/apple/dep: error: package at \'/Users/apple/dep\' is using Swift tools version 3.1.0 which is no longer supported; use 4.0.0 or newer instead\n", output: "")"

I have done the usual stuff like clean-build folder, cleaning derived data etc. Now, what should I do next. If you need any further information, I can post code(s) or screenshot(s).

askit
  • 205
  • 4
  • 21

3 Answers3

6

A somewhat detailed checklist would be …

  1. Check Swift version. Then, if needed, update Xcode for a recent released Swift version on macOS. In Xcode > Preferences > Locations > Command Line Tools, confirm that the Command Line Tools: is pointing to current toolchain version. Xcode 11.3 (11C29) provides 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. If needed, update and upgrade brew to the most recent version. (Or, see https://brew.sh/ if the Homebrew package manager is not yet installed.)
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. Check the vapor/tap tap. Optionally, the tap can be removed and installed again.
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. Now, with the prerequisites in place, install (or reinstall) Vapor 3 vapor via brew. Vapor 4 beta vapor-beta has a github issue.
# 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. Verify.
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]

Oh, Vapor Toolbox 3.1.12 claims to be "3.1.10". See GitHub issue https://github.com/vapor/toolbox/issues/292.

  1. Generate Xcode Project
# still in SomeProjectName terminal working directory
vapor xcode
marc-medley
  • 8,931
  • 5
  • 60
  • 66
  • 1.) Command Line Tools: Xcode 10.2 (10E125). Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)Target: x86_64-apple-darwin18.5.0. 2.) Homebrew 2.2.2 - Homebrew/homebrew-core (git revision 3e10; last commit 2019-12-28). 3.)brew tap # list existing taps - # homebrew/core(no # vapor/tap). vapor/tap - Error: No available tap vapor/tap. – askit Dec 29 '19 at 04:28
  • cotd. from above - 4) brew reinstall vapor==> Reinstalling vapor Warning: Your Xcode (10.2) is outdated.Please update to Xcode 11.3 (or delete it).Error: An exception occurred within a child process:FormulaUnavailableError: No available formula with the name "/usr/local/opt/vapor/.brew/vapor.rb" 5.) swift --version - same as above/no change. vapor --version - Vapor Toolbox: 3.1.10 In order to find the Vapor Framework version of your project, it needs to be built at least once Would you like to build now? y/n> y. Building Project [Failed], which loops back to the main isssue. – askit Dec 29 '19 at 04:56
  • cotd. from above --- brew info vaporvapor: stable 3.1.12 https://vapor.codes/usr/local/Cellar/vapor/3.1.12 (6 files, 17.8MB) * Built from source on 2019-12-10 at 17:35:46 From: /usr/local/opt/vapor/.brew/vapor.rb ==> DependenciesRequired: ctls ✔, libressl ✔Apples-MacBook-Air:de apple$. vapor new SomeProjectName --template=api # or, --template=webcd SomeProjectName vapor build# No .build folder, fetch may take a while...# Fetching Dependencies [Done]# Building Project [Done] .So, the crux is that though my xcode is not updated (4th point), the problem is sorted. – askit Dec 29 '19 at 05:49
  • 1
    you missed a step, perhaps - in the end (last step)I had to regenerate the project using "vapor xcode"in terminal. your steps helped me to solve my issue, thanks. – askit Dec 29 '19 at 06:21
6

In addition to the answer posted by l-marc-l , the first step I had to try was to remove the empty line above "// swift-tools-version:4.0" line i.e. the first line in package.swift, it could have easily sorted my issue. If that would not have sorted the issue, then I would have gone for the steps mentioned by l --marc l.

askit
  • 205
  • 4
  • 21
0

You either need to update the toolbox (brew upgrade vapor) or just run swift build

marc-medley
  • 8,931
  • 5
  • 60
  • 66
0xTim
  • 5,146
  • 11
  • 23
  • I run "brew update vapor",which gives -Error: This command updates brew itself, and does not take formula names.Use brew upgrade vapor instead. So, I run "brew upgrade vapor", which gives- Updating Homebrew...==> Auto-updated Homebrew!.Updated 1 tap (homebrew/core). Warning: vapor/tap/vapor 3.1.12 already installed. Then I run "vapor build" , which gives -vapor build.Building Project [Failed].Command:build/Error (1):/Users/apple/de: error: package at '/Users/apple/de' is using Swift tools version 3.1.0 which is no longer supported; use 4.0.0 or newer instead.Output:Toolchain:/usr/bin/swift – askit Dec 28 '19 at 18:30