6

I have the most recent version of Xcode 9 installed and have reinstalled vapor with brew a couple times now, but I'm still getting the following error whenever I try to build/run/update the project.

Here's what I'm working with

1.) Vapor Toolbox: 3.1.2

2.) Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
    Target: x86_64-apple-macosx10.9

3.) Xcode 9.0
    Build version 9M136h
Error: Could not generate Xcode project: error: manifest parse error(s):
/var/folder/60/n3ldjzgs5vsg06v17_1yy44h0000gn/T/TemporaryFile.VwrbJo.swift:41:5
: error: argument 'targets' must preceed argument 'dependencies'
    targets" [
    ^
error: The product dependency 'Vapor' was not found.
error: The product dependency 'FluentProvider' was not found.
error: The product dependency 'Testing' was not found.

Here is my Package.swift file. Looking at my original error, I did try switching the 'targets' and 'dependencies' order in which they appear in the file. This didn't solve anything and produced the following error message: error: argument 'dependencies' must precede argument 'targets'

Package.swift

let package = Package(
    name: "test",
    products: [
        .library(name: "App", targets: ["App"]),
        .executable(name: "Run", targets: ["Run"])
    ],
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.1.0")),
        .package(url: "https://github.com/vapor/fluent-provider.git", .upToNextMajor(from: "1.2.0")),
    ],
    targets: [
        .target(
            name: "App",
            dependencies: ["Vapor", "FluentProvider"],
            exclude: [
                    "Config",
                    "Public",
                    "Resources",
                    ]
        ),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App", "Testing"])
    ]
)
marc-medley
  • 8,931
  • 5
  • 60
  • 66
Nathan Ortega
  • 538
  • 1
  • 5
  • 17
  • Can you show us your Package.swift file? seems like something is going wrong there. – Mauran Muthiah Nov 12 '17 at 07:37
  • @MauranMuthiah : Thanks for taking a look at my question, I've edited my question to include a screenshot of my Package.swift file. – Nathan Ortega Nov 13 '17 at 01:03
  • Why share it as a screenshot and not actual code? – Andy Ibanez Nov 13 '17 at 01:36
  • @AndyIbanez : Because it's literally a blank starter project, so there is no interesting code to look at. I just wanted to show that the Package.swift file is normal. I'm guessing the issue has to do with my environment setup. – Nathan Ortega Nov 13 '17 at 02:24
  • 1
    In general, you should always post code. If I wanted to edit something and tell you to try it out, I wouldn’t be able to. Except for this case where I’d swap Targets and Dependencies around to see if that fixes it. – Andy Ibanez Nov 13 '17 at 02:27
  • @AndyIbanez: I actually already tried it, but I got the reverse of my original error: ``'dependencies' must precede argument 'targets'``. It's very weird – Nathan Ortega Nov 13 '17 at 02:45
  • The output you are showing in the screenshot is from `vapor xcode` to build your Xcode project. You have run `vapor build` first right? It just looks like you haven't got the dependancies. – TJ Shae Nov 13 '17 at 14:38
  • @TJShae I actually get the same error when running both commands, regardless of the order – Nathan Ortega Nov 13 '17 at 21:27
  • For me: "swift package tools-version --set-current" command solved above issue. And then run "swift package fetch" to fetch data – Shrawan Nov 30 '18 at 07:42

1 Answers1

16

Xcode 12 / Swift 5.3 Update

vapor is now part of homebrew/core. Source: github homebrew-core/Formula/vapor.rb.

##### If applicable, remove the obsolete 'vapor/tap' #####
## List current taps:
brew tap
# homebrew/core
# vapor/tap
## Remove tap:
brew untap vapor/tap

#### Install current version of vapor #####
brew install vapor
brew upgrade vapor

Xcode 9 / Swift 4

  1. Double Check Versions: "the most recent releases" would be at least Xcode 9.1 (9B55) and Apple Swift 4.0.2 (swiftlang-900.0.69.1 clang-900.0.38)

  2. Verify that the first line in Packages.swift is // swift-tools-version:4.0. Without swift-tools-version line, Packages.swift could be processed as swift-tools-version 3. which will cause an error.*

cd _PROJECT_PATH_
swift package tools-version
# if not 4.0.0, then …
swift package tools-version --set-current

An example, Package.swift is shown below. See Swift Package Manager Manifest API Redesign and swift-package-manager Usage Documentation for additional information.

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift
// required to build this package. 
// Syntax: '// swift-tools-version:<specifier>' on the 1st line

import PackageDescription

let package = Package(
    name: "test",
    products: [
        .library(name: "App", targets: ["App"]),
        .executable(name: "Run", targets: ["Run"])
    ],
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.3.0")),
        .package(url: "https://github.com/vapor/fluent-provider.git", .upToNextMajor(from: "1.3.0")),
    ],
    targets: [
        .target(
            name: "App",
            dependencies: ["Vapor", "FluentProvider"],
            exclude: [
                    "Config",
                    "Public",
                    "Resources",
                    ]
        ),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: ["App", "Testing"])
    ]
)
  1. Recheck
cd _PROJECT_PATH_
swift package tools-version
# should be 4.0.0

vapor clean
vapor update
vapor --version

# Vapor Toolbox: 3.1.2
# Vapor Framework: 2.3.0
  1. Try to build again.

More notes are posted on StackOverflow here for using Xcode 9 and Swift 4 with Vapor 2.

The GitHub repository Vapor Examples Lab has several example projects which have been migrated to Vapor 2 and Swift 4.

marc-medley
  • 8,931
  • 5
  • 60
  • 66
  • Thanks! But how can a comment (// swift-tools-version:4.0) affect the execution at all? I was missing this line, adding it solved the deploy error I had. The Vapor implementation is quite hacky if it looks a value in a comment... This would be the last thing I think about... a comment that affects the execution. – balazs630 Nov 20 '18 at 16:02
  • 1
    @balazs630 `// swift-tools-version:` was added as a standard part of the [Swift Package Manager Manifest API](https://swift.org/blog/swift-package-manager-manifest-api-redesign/) in June 2017. Some related info and links are now added to step 2 in this answer. – marc-medley Nov 20 '18 at 21:00