I'm trying to set up basic project using servant and stack loosely following official servant tutorial and stack guide. As soon as I add import Servant
stack build fails with:
Could not find module ‘Servant’
Use -v to see a list of the files searched for.
I've defined servant
as a dependency of this module and stack noticed it as stack dependencies
shows:
aeson 0.8.0.2
array 0.5.1.0
attoparsec 0.12.1.6
base 4.8.1.0
binary 0.7.5.0
blaze-builder 0.4.0.1
bytestring 0.10.6.0
bytestring-conversion 0.3.1
case-insensitive 1.2.0.4
containers 0.5.6.2
deepseq 1.4.1.1
dlist 0.7.1.2
double-conversion 2.0.1.0
ghc-prim 0.4.0.0
hashable 1.2.3.3
http-media 0.6.2
http-types 0.8.6
integer-gmp 1.0.0.0
mtl 2.2.1
network-uri 2.6.0.3
parsec 3.1.9
primitive 0.6
scientific 0.3.3.8
servant 0.4.4.2
string-conversions 0.4
syb 0.5.1
template-haskell 2.10.0.0
text 1.2.1.3
tforia-products 0.1.0.0
time 1.5.0.1
transformers 0.4.2.0
unordered-containers 0.2.5.1
utf8-string 1.0.1.1
vector 0.10.12.3
Code of module:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
module API
( ProductAPI
, apiServer
) where
import Data.Aeson
import GHC.Generics
import Servant
data Product = Product
{ id :: String
, name :: String
} deriving (Eq, Show, Generic)
instance ToJSON Product
products :: [Product]
products =
[ Product "id123" "shoes of some guy"
, Product "id234" "hat of some gal"
]
type ProductAPI = "products" :> Get '[JSON] [Product]
apiServer :: Server UserAPI
apiServer = return products
Cabal definition of module:
library
hs-source-dirs: src
exposed-modules: API
build-depends: base >= 4.7 && < 5
, servant
, aeson
default-language: Haskell2010
I have no idea where else I have to define that dependency so stack/cabal is able to pick it up.
The Servant
module comes from servant-server, as you can see here in the module list. The handy Servant
module reexports everything from the servant package (which has all the types to describe web APIs) as well as the key things for running servant web apps.
Long story short: you need to add the servant-server package to your dependencies as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With