获取“找不到模块'Yesod'”当我尝试运行Yesod书中的第一个示例时 [英] Getting "Could not find module `Yesod'" when I try to run first example from Yesod book

查看:131
本文介绍了获取“找不到模块'Yesod'”当我尝试运行Yesod书中的第一个示例时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这似乎是重复的找不到模块'Yesod',但与该用户不同, ghc-pkg list 在我的计算机输出中不显示 Yesod ,但他们没有似乎是使用 stack (我是,我不确定这是否意味着我不需要担心 ghc-pkg list ),此外,该问题的答案(代码)无助于我的情况。 Yesod Book 有一个示例,我一直试图现在工作几个小时。

  { - #LANGUAGE OverloadedStrings# - } 
{ - #LANGUAGE QuasiQuotes# - }
{ - #LANGUAGE TemplateHaskell# - }
{ - #LANGUAGE TypeFamilies# - }
导入Yesod

数据HelloWorld = HelloWorld

mkYesodHelloWorld[parseRoutes |
/ HomeR GET
|]

实例Yesod HelloWorld

getHomeR :: Handler Html
getHomeR = defaultLayout [whamlet | Hello World! |]
$ b $ main main :: IO()
main = warp 3000 HelloWorld

我正在使用最新的64位Ubuntu操作系统。我一直遇到的问题是 runhaskell hello-world.hs 会一次又一次返回

  hello-world.hs:6:18:
无法找到模块'Yesod'
使用-v查看搜索文件的列表。

同样,当我添加模块名称该文件并尝试使用堆栈ghci hello-world.hs 加载它。我使用 stack 来构建东西,并且我尝试了许多不同的迭代 stack new (使用yesod模板), stack init stack build 的左侧和右侧,用 stack update 在这里和那里有很好的衡量标准,甚至还有一些 cabal install ,以及整个 $ / $。 b

当我在 simpleSQL 中使用Yesod模板时,模板网站会正确加载,而且我正在使用一个更大的项目 Snowdrift ,也可以运行(尽管作为一个站点,使用 stack exec yesod devel 而不是 runhaskell FILE 命令;但仍然有效,并且我尝试了完全相同的构建过程来处理<$ c上面的$ c> hello-world.hs 文件。



我觉得这个问题有一个简单的解决方案,我错过了,但我试过了,试过了,并且搜遍了,而我只是没有来通过一个答案。



感谢大家抽出宝贵时间帮助我。 p> runhaskell hello-world.hs ghc-pkg list 将默认使用全局系统和用户包数据库(也就是cabal-instal通常使用的那些),而不是堆栈使用的快照和项目特定的快照(另请参阅:为什么不会将包添加到ghc包数据库?)。你应该使用 stack runghc hello-world.hs stack exec - ghc-pkg list 。堆栈命令确保GHC工具使用适当的包数据库(以及GHC的相应版本,以防需要堆栈设置使用不同于GHC的GHC系统安装)。

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.

解决方案

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).

这篇关于获取“找不到模块'Yesod'”当我尝试运行Yesod书中的第一个示例时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆