我使用 Vapor 創建了一個應用程式,我想將它部署到 Heroku,但推送失敗。
構建配置看起來像這樣
- .swift 版本:5.5
- 使用 heroku-buildpack
日志如下所示。
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: https://github.com/vapor-community/heroku-buildpack
remote: -----> Swift app detected
remote: -----> Using Swift 5.5 (from .swift-version file)
remote: -----> Using built-in clang (Swift 5.5)
remote: -----> Installing swiftenv
remote: -----> Installing Swift 5.5
remote: Downloading https://swift.org/builds/swift-5.5-release/ubuntu2004/swift-5.5-RELEASE/swift-5.5-RELEASE-ubuntu20.04.tar.gz
remote: /tmp/swiftenv-5.5- /tmp/codon/tmp/buildpacks/66275d05cfaec82f8023e1ae68b013a22671c52f
.
.
.
remote: /tmp/build_ecf900fb/Sources/App/APIClient/APIClient.swift:61:34: error: value of type 'URLSession' has no member 'data
remote: return try await session.data(for: request, delegate: nil)
remote: ~~~~~~~ ^~~~
remote: /tmp/build_ecf900fb/Sources/App/APIClient/APIClient.swift:61:63: error: 'nil' requires a contextual type
remote: return try await session.data(for: request, delegate: nil)
remote: ^
remote: ! Push rejected, failed to compile Swift app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to apple-dev-news-ios.
remote:
To https://git.heroku.com/apple-dev-news-ios.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/apple-dev-news-ios.git'
APIClient.swift:61:63:
private let session: URLSession
.
.
.
private func actuallySend(_ request: URLRequest) async throws -> (Data, URLResponse) {
.
.
.
return try await session.data(for: request, delegate: nil)
}
為什么它會失敗,我們如何才能使推送成功?
“資料”在 Foundation 框架中定義如下。
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
extension URLSession {
/// Convenience method to load data using an URLRequest, creates and resumes an URLSessionDataTask internally.
///
/// - Parameter request: The URLRequest for which to load data.
/// - Parameter delegate: Task-specific delegate.
/// - Returns: Data and response.
public func data(for request: URLRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse)
.
.
.
uj5u.com熱心網友回復:
Linux 上 Foundation 的異步 API 尚不可用(它們與實際的語言并發功能不同)。
對于 Vapor 應用程式,您不應該真正使用 URLSession 來發出請求,它不適合框架的作業方式。改用 Vapor 的客戶端(具有異步 API)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/385933.html
