无法为Cabal项目添加digestive-functors库,求构建解决方案
Cabal项目依赖冲突解决(text与digestive-functors)
问题背景
原本可正常构建的Cabal项目,添加text >=2.0.0和digestive-functors >=0.8.3.0依赖后,出现依赖解析失败,无法完成构建。
项目Cabal配置
library import: warnings exposed-modules: MyLib , Logger , Domain.Auth , Domain.Validation , Adapter.InMemory.Auth , Adapter.PostgreSQL.Auth , Adapter.Redis.Auth , Adapter.RabbitMQ.Common , Adapter.RabbitMQ.Auth default-extensions: ConstraintKinds , FlexibleContexts , NoImplicitPrelude , OverloadedStrings , QuasiQuotes , TemplateHaskell -- other-modules: -- other-extensions: build-depends: base >= 4.18.0.0 , katip >= 0.8.7.0 , text >= 2.0.0 , digestive-functors >= 0.8.3.0 , string-random , mtl , data-has , classy-prelude , pcre-heavy , time , time-lens , resource-pool , postgresql-simple , exceptions , postgresql-migration , extra , hedis , amqp , aeson , lifted-base , scotty , http-types , cookie , wai , wai-extra , blaze-builder hs-source-dirs: src default-language: GHC2021
构建错误日志
cabal build Resolving dependencies... Error: [Cabal-7107] Could not resolve dependencies: [__0] trying: practical-web-dev-ghc-0.1.0.0 (user goal) [__1] trying: text-2.1.1/installed-05f2 (dependency of practical-web-dev-ghc) [__2] trying: template-haskell-2.22.0.0/installed-e0ca (dependency of text) [__3] next goal: digestive-functors (dependency of practical-web-dev-ghc) [__3] rejecting: digestive-functors-0.8.4.2 (conflict: text => bytestring==0.12.1.0/installed-5f32, digestive-functors => bytestring>=0.9 && <0.12) [__3] rejecting: digestive-functors-0.8.4.0 (conflict: text => bytestring==0.12.1.0/installed-5f32, digestive-functors => bytestring>=0.9 && <0.11) [__3] rejecting: digestive-functors-0.8.3.0 (conflict: text => base==4.20.0.0/installed-380b, digestive-functors => base>=4 && <4.11) [__3] rejecting: digestive-functors-0.8.2.0 (conflict: practical-web-dev-ghc => digestive-functors>=0.8.3.0) [__3] skipping: digestive-functors; 0.8.1.1, 0.8.1.0, 0.8.0.1, 0.8.0.0, 0.7.1.5, 0.7.1.4, 0.7.1.3, 0.7.1.2, 0.7.1.1, 0.7.1.0, 0.7.0.0, 0.6.2.0, 0.6.1.1, 0.6.1.0, 0.6.0.1, 0.6.0.0, 0.5.0.4, 0.5.0.3, 0.5.0.2, 0.5.0.1, 0.5.0.0, 0.4.1.2, 0.4.1.1, 0.4.1.0, 0.4.0.0, 0.3.2.1, 0.3.1.0, 0.3.0.2, 0.3.0.1, 0.3.0.0, 0.2.1.0, 0.2.0.1, 0.2.0.0, 0.1.0.2, 0.1.0.1, 0.1.0.0, 0.0.2.1, 0.0.2.0, 0.0.1 (has the same characteristics that caused the previous version to fail: excluded by constraint '>=0.8.3.0' from 'practical-web-dev-ghc') [__3] fail (backjumping, conflict set: digestive-functors, practical-web-dev-ghc, text) After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: text, practical-web-dev-ghc, digestive-functors, template-haskell, base Try running with --minimize-conflict-set to improve the error message.
已尝试调整digestive-functors和text的多个版本,但问题未解决。
解决方案
方案1:降级text版本适配旧版digestive-functors
从错误日志可知,digestive-functors 0.8.x系列的依赖限制较严格:
- 0.8.3.0要求
base <4.11,但当前项目使用base >=4.18 - 0.8.4.x要求
bytestring <0.12,但text 2.x依赖bytestring >=0.12
修改Cabal配置中的build-depends部分,调整text和digestive-functors的版本范围:
text >=1.2 && <2.0, digestive-functors >=0.8.4.2 && <0.9
text 1.x系列依赖的bytestring版本符合digestive-functors 0.8.4.2的要求,同时能兼容项目的base版本。
方案2:升级digestive-functors到支持新依赖的版本
digestive-functors 0.9.x及以上版本已更新依赖限制,支持base >=4.11和bytestring >=0.12,可直接适配text 2.x和当前项目的base版本。修改依赖如下:
text >=2.0.0, digestive-functors >=0.9.0.0
注意:需确认项目代码兼容digestive-functors 0.9.x的API变化。
方案3:锁定依赖版本避免解析冲突
修改依赖后,执行以下命令锁定所有依赖的具体版本:
cabal freeze
生成cabal.project.freeze文件后,再执行cabal build即可完成构建。
内容的提问来源于stack exchange,提问作者user51
相关产品推荐
相关产品推荐

