I know this seems a duplicate to Could not find module `Yesod', but unlike that user, ghc-pkg list
does not show Yesod
in its output on my computer, they didn't seem to be using stack
(I am, and I'm not sure if that means I don't need to worry about ghc-pkg list
), and additionally, the answer (code) to that question did not help my situation.
The Yesod Book has an example that I've been trying to get to work for several hours now. I'll reprint it here
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Yesod
data HelloWorld = HelloWorld
mkYesod "HelloWorld" [parseRoutes|
/ HomeR GET
|]
instance Yesod HelloWorld
getHomeR :: Handler Html
getHomeR = defaultLayout [whamlet|Hello World!|]
main :: IO ()
main = warp 3000 HelloWorld
I'm using the latest 64-bit Ubuntu OS. The problem I consistently run into is that runhaskell hello-world.hs
will time-and-time again return
hello-world.hs:6:18:
Could not find module `Yesod'
Use -v to see a list of the files searched for.
Likewise when I add a module
name to the file and try loading it with stack ghci hello-world.hs
. I'm using stack
to build things, and I've tried many different iterations of stack new
(with yesod templates), stack init
, and stack build
's left and right, with stack update
's here and there for good measure, and even a few cabal install
's, along with the entirety of the Yesod quickstart guide, all to no avail, and all within the proper directories.
When I use Yesod templates with simpleSQL
, the template site loads properly, and moreover a much larger project that I'm working with, Snowdrift, runs as well (albeit as a site, using stack exec yesod devel
and not a runhaskell FILE
command; but still, it works, and I've tried the exact same build process for handling the hello-world.hs
file above.
I feel like this problem has a simple solution that I'm missing, but I've tried and tried, and searched all over, and I just haven't come across an answer.
Thanks a bunch for taking the time to help me out.
Your results may vary, but this worked for me (on 13 Jan 2018):
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".
runhaskell hello-world.hs
andghc-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 usestack runghc hello-world.hs
andstack 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 astack setup
to use a different GHC than the one installed system-wide).