Florin Odagiu
Florin Odagiu

Reputation: 516

Not able to create a valid, working, new project while using Vapor4

My context:

I'm creating a new Vapor project with vapor-beta new myProjectName

It asks if I want to use Fluent, which I agree to (y) and asks what kind of database do I want (1. postgreSQL 2. MySql 3. SQLite). I went with option 3; SQLite is what I need.

It then proceeds to download a template and supposedly customise it with my above selected options. It stops / freezes at

Generating project files
+ Package.Swift

Nothing happens after this line, even after 10 minutes of waiting.

When I look in my application folder, there's a hidden .vapor-template folder that seems to contain the folder structure of an app. I can't simply start using it, because many files seem to be...unfinished, in some way. For instance, here's how Package.swift looks like:

let package = Package(
    name: "{{name}}",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-rc"){{#fluent}},
        .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent-{{fluent.db.url}}-driver.git", from: "{{fluent.db.version}}-rc"){{/fluent}}
    ],
    targets: [
        .target(name: "App", dependencies: [{{#fluent}}
            .product(name: "Fluent", package: "fluent"),
            .product(name: "Fluent{{fluent.db.module}}Driver", package: "fluent-{{fluent.db.url}}-driver"),{{/fluent}}
            .product(name: "Vapor", package: "vapor")
        ]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)

As you can see, the name of the project is not set (I'm referring to the name: "{{name}}" thing), and there are plenty of weird references to {{#fluent}} or "{{fluent.db.version}}-rc") that freak out the compiler. It looks like the "vapor new" command had some more customisation work to do that it simply did not get a chance to finish. Same story repeats in configure.swift and routes.swift.

I did comb through all of them, deleting the weird placeholders only to bump into some configure.swift situation where it complains about .sqlite not being recognised or something. I did look it up on google / stackoverflow, tried some fixes that didn't work...until I took a step back an realised that hell...I shouldn't be doing all this SherlokHolmes-ing...the "vapor new" command should simply work and successfully finish...There's plenty of work for me afterwards...This simple, helloWorld-ish step should simply work...

If anyone has some insights into successfully creating a Vapor4 project, I'll be grateful...(simply following the steps at https://docs.vapor.codes/4.0/hello-world/ is not conducive to a working project)

L.E: thanks to imike's suggestion, I headed over to Vapor's community on Discord and found my solution. My project's folder path happened to contain some spaces and dashes. Removing those allowed the process to finish correctly. Great, helpful community!

Upvotes: 2

Views: 234

Answers (1)

imike
imike

Reputation: 5656

it looks like something is wrong with templating system.

You could fix your Package.swift by yourself

let package = Package(
    name: "YourProject",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0-rc"),
        .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0-rc")
    ],
    targets: [
        .target(name: "App", dependencies: [
            .product(name: "Fluent", package: "fluent"),
            .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
            .product(name: "Vapor", package: "vapor")
        ]),
        .target(name: "Run", dependencies: ["App"]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)

Upvotes: 1

Related Questions