Stack新手构建并发网页抓取工具时的依赖配置问题
Hey there! Let’s work through these Stack dependency hurdles together—building a concurrent web scraper is a fun project, so let’s get those dependencies sorted out.
First: Fix the allow-newer Placement
You mentioned adding allow-newer: true under the executable section didn’t work—that makes sense! allow-newer is a global/package-level setting, not an executable-specific one. You have two better options:
Option 1: Add it to your
stack.yaml(recommended)
Open your project’sstack.yamlfile and add this line at the top level:allow-newer: trueThis applies the setting to your entire project, which is more flexible than putting it in the cabal file.
Option 2: Add it to the top of
my-project.cabal
If you prefer keeping it in the cabal file, place it before theexecutableblock:allow-newer: true executable my-project ...
Second: Correct Your Dependency Syntax
Writing http == * triggers a parsing error because Cabal doesn’t allow unconstrained == wildcards. Instead, use one of these approaches for your build-depends section in my-project.cabal:
Allow any compatible version (simplest for beginners):
build-depends: base >= 4.14 && < 5, hxt, url, http, maybetStack will automatically pick the version of
httpthat’s compatible with your resolver.Specify a minimum version if you need features from a newer release:
build-depends: base >= 4.14 && < 5, hxt, url, http >= 4000.3.9, maybet
Third: Resolve the "http 4000.3.9 Not Found" Error
When you specified http == 4000.3.9, Stack complained because that version isn’t included in your current resolver (the set of package versions Stack uses by default). Here’s how to fix this:
- Check your current resolver by running:
stack resolver - See which
httpversions are available in your resolver:stack exec ghc-pkg list http - If you really need 4000.3.9, add it as an
extra-depinstack.yaml:
This tells Stack to fetch and use that specific version even if it’s not in the resolver.extra-deps: - http-4000.3.9
Alternatively, you could switch to a resolver that includes http-4000.3.9, but using extra-deps is usually easier for one-off package version overrides.
I remember tripping over these exact dependency issues when I first started with Stack—once you get the hang of resolvers and extra-deps, it gets way smoother. Good luck with your web scraper!
内容的提问来源于stack exchange,提问作者Mark Karavan

