Swift Error Message : "error: no executable product named 'App'" when executing swift run command in Terminal

huangapple go评论67阅读模式
英文:

Swift Error Message : "error: no executable product named 'App'" when executing swift run command in Terminal

问题

I'm attempting to run a swift command on a Vapor/Fluent app that in the past has been unproblematic. I'm running swift run App migrate, which normally updates any migrations. But it's throwing the error that is in the title.

我正在尝试在过去从未出现问题的 Vapor/Fluent 应用程序上运行 Swift 命令。我运行 swift run App migrate,通常会更新任何迁移。但是它抛出了标题中的错误。

I've looked at the Package file and it's got:

我查看了 Package 文件,内容如下:

 targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Vapor", package: "vapor"),
                .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
                .product(name: "Fluent", package: "fluent"),
                .product(name: "Leaf", package: "leaf"),
//                .product(name: "SendGrid", package: "sendgrid"),
            ],
            swiftSettings: [
                // Enable better optimizations when building in Release configuration. -- Despite the use of
                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
                // builds. See <https://github.com/swift-server/guides#building-for-production> for details.
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
            ]
        ),
       
        .target(name: "Run", dependencies: [.target(name: "App")]), // comment what follows
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
        // to here
    ]

while the name at the top is something different. I have tried reentering the command with the name set in the package section, and that makes no difference.

然而,顶部的名称不同。我尝试重新输入在 package 部分设置的名称的命令,但没有任何改变。

I've tried the same thing with multiple other projects that are similar, including ones that haven't been changed for months, and worked before, and I get the same error. Attempting to install Command Line Tools says everything is up to date. And resetting Xcode to the standard path (it was never changed) does nothing...

我尝试在多个类似的其他项目上尝试了相同的操作,包括那些几个月没有更改并且之前正常工作的项目,但我仍然收到相同的错误。尝试安装命令行工具显示一切都是最新的。将 Xcode 重置为标准路径(从未更改过)也没有效果...

I'm at a bit of a loss on this one... any answers greatly appreciated.

我有点困惑...非常感谢任何答案。

英文:

I'm attempting to run a swift command on a Vapor/Fluent app that in the past has been unproblematic. I'm running swift run App migrate, which normally updates any migrations. But it's throwing the error that is in the title.

I've looked at the Package file and it's got:

 targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Vapor", package: "vapor"),
                .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
                .product(name: "Fluent", package: "fluent"),
                .product(name: "Leaf", package: "leaf"),
//                .product(name: "SendGrid", package: "sendgrid"),
            ],
            swiftSettings: [
                // Enable better optimizations when building in Release configuration. -- Despite the use of
                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
                // builds. See <https://github.com/swift-server/guides#building-for-production> for details.
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
            ]
        ),
       
        .target(name: "Run", dependencies: [.target(name: "App")]), // comment what follows
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
        // to here
    ]

while the name at the top is something different. I have tried reentering the command with the name set in the package section, and that makes no difference.

I've tried the same thing with multiple other projects that are similar, including ones that haven't been changed for months, and worked before, and I get the same error. Attempting to install Command Line Tools says everything is up to date. And resetting Xcode to the standard path (it was never changed) does nothing...

I'm at a bit of a loss on this one... any answers greatly appreciated.

答案1

得分: 1

在某个时候,似乎Swift工具已更改以期望executableTargetName("Run")作为您运行的内容,而不是targetName("App")。

因此,对于您的示例(以及我的Vapor项目,这是我找到解决方法的方式),现在不再需要运行swift run App migrate,而是需要运行swift run Run migrate

英文:

At some point, it seems the swift tooling changed to expect the executableTargetName ("Run") for what you're running rather than the targetName ("App").

So for your example (and my vapor project which is how I figured this out) instead of running swift run App migrate, you now need to run swift run Run migrate

huangapple
  • 本文由 发表于 2023年7月6日 22:11:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629727.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定