堆栈新命令无法下载 lts-14.1 的构建计划

stack new command failing to download build plan for lts-14.1

Stack 以 404 HTTP 状态下载 lts-14.1 的构建计划失败:

$ stack new my-project

[...]

Downloading lts-14.1 build plan ...
RedownloadInvalidResponse Request {
  host                 = "raw.githubusercontent.com"
  port                 = 443
  secure               = True
  requestHeaders       = []
  path                 = "/fpco/lts-haskell/master//lts-14.1.yaml"
  queryString          = ""
  method               = "GET"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 10
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
}
 "/home/michid/.stack/build-plan/lts-14.1.yaml" (Response {responseStatus = Status {statusCode = 404, statusMessage = "Not Found"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Security-Policy","default-src 'none'; style-src 'unsafe-inline'; sandbox"),("Strict-Transport-Security","max-age=31536000"),("X-Content-Type-Options","nosniff"),("X-Frame-Options","deny"),("X-XSS-Protection","1; mode=block"),("X-GitHub-Request-Id","10DA:4457:1D507:285B9:5D55DA2D"),("Content-Length","15"),("Accept-Ranges","bytes"),("Date","Thu, 15 Aug 2019 22:18:21 GMT"),("Via","1.1 varnish"),("Connection","keep-alive"),("X-Served-By","cache-mxp19828-MXP"),("X-Cache","MISS"),("X-Cache-Hits","0"),("X-Timer","S1565907502.529821,VS0,VE176"),("Vary","Authorization,Accept-Encoding"),("Access-Control-Allow-Origin","*"),("X-Fastly-Request-ID","9f869169dd207bbd8bb8a8fd4b274acf6580ba4f"),("Expires","Thu, 15 Aug 2019 22:23:21 GMT"),("Source-Age","0")], responseBody = (), responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose})

如果我在命令行中指定 --resolver lts-13.19 一切正常,所以我假设这是一个错误。

回答我自己的问题:

原来我使用的是旧版本的 stack。通过

升级后
stack upgrade 

一切正常。

错误消息令人困惑,因为它没有说明 404 错误的任何原因。这可能是由于 Stack 的版本错误。要检查这一点,请键入:

stack --version

此命令不仅会告诉您安装了哪个版本,还会告诉您什么是最新版本。如果您的版本不是最新的,而且如果您的版本是 "unsupported" 版本,它可能会显示一条消息,例如

Warning: this is an unsupported build that may use different versions of
dependencies and GHC than the officially released binaries, and therefore may
not behave identically.  If you encounter problems, please try the latest
official build by running 'stack upgrade --force-download'.

只要按照说明去做就可以了:

stack upgrade --force-download

您可能会收到一条消息,指出复制到 /usr/bin 时出错,并询问您是否要使用 sudo 重试。只需接受并输入您的 sudo 密码。

通过键入以下内容检查新的升级版本现在是否是最新的:

stack -version

我遇到了和OP类似的情况,但是在stack upgrade之后我仍然报错;它仅在启动一个新终端后才消失(在 macOS 上)。