"stack setup --upgrade-cabal" 失败,无法找到 Text.Parsec

"stack setup --upgrade-cabal" fails, can't find Text.Parsec

使用 stack new testProject 创建新项目后,我编辑了 testProject.cabal 以使用最新版本的 Cabal:

cabal-version:  2.2.0.0

运行 stack setup --upgrade-cabal 之后产生错误:

[ 12 of 216] Compiling Distribution.Compat.Parsing ( Distribution/Compat/Parsing.hs, Distribution/Compat/Parsing.o )

Distribution/Compat/Parsing.hs:61:1: error:
    Could not find module ‘Text.Parsec’
    Use -v to see a list of the files searched for.
   |
61 | import qualified Text.Parsec as Parsec
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exit code ExitFailure 1 while running ["ghc","Setup.hs"] in /tmp/stack-cabal-upgrade30389/Cabal-2.2.0.0/

我在 Arch Linux 4.15.3,stack --version 给出

Version 1.6.3, Git revision b27e629b8c4ce369e3b8273f04db193b060000db (5454 commits) x86_64 hpack-0.20.0

stack ghc -- --version:

The Glorious Glasgow Haskell Compilation System, version 8.2.2

如何解决此错误并使用 Stack 升级 Cabal?

出现您描述的问题是因为:

  1. Cabal 2.2.0.0 与早期版本不同,它具有 parsec 作为依赖项。考虑到这一点,parsec is one of the core packages bundled with GHC from GHC 8.4.1 onwards.

  2. stack setup --upgrade-cabal 在 "global" 级别安装 Cabal,即 cross-snapshot 但绑定到 GHC 版本。因此,它只使用与 GHC 捆绑在一起的包(而不是任何快照中的包)。有关这一点的讨论,请参阅 Stack issue #3049 和其中链接的其他问题。

既然如此,我认为这个问题没有解决方案,除非您愿意将您的项目更改为使用 GHC 8.4.1 的 resolver/snapshot。

P.S.: 除非您需要特定的 Cabal 功能或 2.2.0.0 中包含的错误修复,否则您可能需要重新考虑是否真的要升级 阴谋集团。引用 Stack user guide:

stack setup --upgrade-cabal can install a newer version of the Cabal library, used for performing actual builds. You shouldn't generally do this, since new Cabal versions may introduce incompatibilities with package sets, but it can be useful if you're trying to test a specific bugfix.