Getting “Could not find module `Yesod'” when I try to run first example from Yesod book

北城余情 提交于 2019-12-06 10:47:26
duplode

runhaskell hello-world.hs and ghc-pkg list will default to using the global system and user package databases (that is, the ones cabal-instal normally uses), and not the snapshot and project-specific ones used by stack (see also: Why doesn't stack add packages to the ghc package database?). You should instead use stack runghc hello-world.hs and stack exec -- ghc-pkg list. The stack commands ensure the GHC tools use the appropriate package databases (and also the appropriate versions of GHC, in case you ever need a stack setup to use a different GHC than the one installed system-wide).

Your results may vary, but this worked for me (on 13 Jan 2018):

  • Mac OS 10.13.2 (High Sierra)
  • Searched Hackage for Yesod, found 1.4.5 at https://hackage.haskell.org/package/yesod-1.4.5/docs/Yesod.html
  • stack install yesod-1.4.5
  • Got dependency error with suggestion to add conduit-extra-1.1.13.1 to extra-deps (in ~/.stack/global/stack.yaml).
  • Tried again; got more dependency errors, with the result being that I ended up with:
  • extra-deps: ["gtk-mac-integration-0.3.4.0","conduit-extra-1.2.3.2","conduit-1.2.13","streaming-commons-0.1.18","typed-process-0.2.1.0","unliftio-core-0.1.1.0"] (You might get different recommendations; I just followed the ones I got. Note: I already had the gtk-mac-integration extra-dep before I started).
  • successfully stack-installed yesod-1.4.5
  • stack runghc helloworld.hs
  • success!

In hindsight, it should seem obvious that module "Yesod" would not be found it it had not yet been installed. I usually work within a stack-created Haskell project, and in that case would have taken the usual steps to ensure the dependency was present. I usually don't run applications with "stack runghc".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!