# Stack: Failures, Errors, Frustrations

**URL:** <https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761>\
**Category:** Learn\
**Created:** [July 13, 2022, 6:37am UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761 "2022-07-13T06:37:53Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [July 13, 2022, 1:36pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/21 "2022-07-13T13:36:22Z")

</div>

I think that should already work for `aeson` and `random`, but you should still add those GTK dependencies:

```haskell
dependencies:
- base
- classy-prelude
- time
- aeson
- random
- gi-gtk == 3.0.*
- gi-gtk-hs
- haskell-gi-base

```

Does that work? If not, what is the full error message you get?

Edit: Oh wait, maybe I see what is going wrong with `random` and `aeson`. Do you literally mean it says “Could not find module ‘aeson’”? Then you have probably written `import aeson`. That is not the correct way to do it. You see, ‘aeson’ is the _package_ name while you can only use import with _module_ names. You probably want to write `import Data.Aeson` which is the main _module_ of the aeson _package_. Similarly you probably want to `import System.Random` from the random _package_.

You can see all the modules in a package on [hackage](https://hackage.haskell.org), e.g. [`aeson`](https://hackage.haskell.org/package/aeson) and [`random`](https://hackage.haskell.org/package/random). There you can also find documentation on how to use these packages.

---

<div class="post-metadata">

**Author:** ![dalendisto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dalendisto/32/2434_2.png) [@dalendisto](https://discourse.haskell.org/u/dalendisto)\
**Post date:** [July 13, 2022, 1:56pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/22 "2022-07-13T13:56:02Z")

</div>

No no, I mported with

System.Random and Data.Aeson.

Still, when I hover over it or do ghci from the file directly I get these messages. Strange though, that I can use functions from these modules and the program compiles…

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [July 13, 2022, 2:01pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/23 "2022-07-13T14:01:45Z")

</div>

> [@dalendisto](#):
>
> Still, when I hover over it or do ghci from the file directly I get these messages. Strange though, that I can use functions from these modules and the program compiles…

What are you doing exactly that causes the warnings? Are you saying `stack build` works correctly but some use of GHCi is giving these errors? And what are you using for hovering, VSCode + HLS?

---

<div class="post-metadata">

**Author:** ![dalendisto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dalendisto/32/2434_2.png) [@dalendisto](https://discourse.haskell.org/u/dalendisto)\
**Post date:** [July 13, 2022, 2:10pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/24 "2022-07-13T14:10:30Z")

</div>

Exactly. If I use stack ghci and test out functions, everything works and compiles. Then I once cd into the file and tried the same just using ghci. Immediatly I get these errors. Yes, VSCode + HLS. I was suspecting that there is some issue with VSCode but the error should not be present when trying to load a file into ghci…really I dont know. I am happy getting stuff done in Haskell but I am pretty fresh to all this setup stuff…

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [July 13, 2022, 2:19pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/25 "2022-07-13T14:19:30Z")

</div>

Ah, so the problem is that normal GHCi doesn’t know anything about your stack project, so in particular it doesn’t have access to the dependencies. It may be possible to just use `stack ghci path/to/YourFile.hs` to load it with the proper dependencies or alternatively you can try `stack exec ghci -- path/to/YourFile.hs`. I don’t know that much about Stack, so I’m not sure what works.

VSCode + HLS should automatically be able to detect your Stack project. I don’t know why that is not working for you.

---

<div class="post-metadata">

**Author:** ![dalendisto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dalendisto/32/2434_2.png) [@dalendisto](https://discourse.haskell.org/u/dalendisto)\
**Post date:** [July 13, 2022, 2:28pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/26 "2022-07-13T14:28:44Z")

</div>

Me neither 😂. Anyway, thank you so much for your time and effort. Maybe I’ll figure it out somehow. I will post the solution or what I am doing wrong once I have it sorted out.

---

<div class="post-metadata">

**Author:** ![mjrussell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/mjrussell/32/2423_2.png) [@mjrussell](https://discourse.haskell.org/u/mjrussell)\
**Post date:** [July 15, 2022, 1:41am UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/27 "2022-07-15T01:41:25Z")

</div>

When using HLS with stack you might need to generate a hie.yaml. The HLS docs say it’s not necessary but I’ve found it’s helped some projects [Configuration — haskell-language-server 1.7.0.0 documentation](https://haskell-language-server.readthedocs.io/en/latest/configuration.html).

Also, make sure with vscode that you have the folder containing stack.yaml as the root in your workspace or use multiple workspaces in vscode so that you’ve added the top level folder to vscode.

If you are still having issues, try checking the extension logs for HLS in vscode.

---

<div class="post-metadata">

**Author:** ![dalendisto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dalendisto/32/2434_2.png) [@dalendisto](https://discourse.haskell.org/u/dalendisto)\
**Post date:** [July 15, 2022, 9:21am UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/28 "2022-07-15T09:21:49Z")

</div>

Ok, maybe I messed something up during installation of Haskell. So I completely removed Haskell as it was installed via GHCup. I use VSCode ++ HLS

Uninstall:  
1: ghcup nuke  
2: removed any ghcup lines in .bashrc  
3: removed .stack, .ghc and .cabal files from my home directory  
4: removed stack from /usr/local/bin directory.

Install:  
1: copied and pasted “curl --proto ‘=https’ --tlsv1.2 -sSf [https://get-ghcup.haskell.org](https://get-ghcup.haskell.org) | sh”  
2: followed the instruction on the terminal

New Project as per [User guide - The Haskell Tool Stack](https://docs.haskellstack.org/en/stable/GUIDE/#adding-dependencies:)  
1: stack new helloworld new-template  
2: cd helloworld  
3: stack build  
4: ghc --version :: The Glorious Glasgow Haskell Compilation System, version 8.10.7  
5: stack setup  
6: Modify Lib.hs according to Stack User guide Adding Dependencies  
7: stack build  
8: Adding -text to dependencies in package.yaml

```haskell
dependencies:
- base >= 4.7 && < 5
- text

```

9: stack build  
10: adding -filepath and - containers

```haskell
dependencies:
- base >= 4.7 && < 5
- text
- filepath
- containers

```

11: stack build  
12: add -classy-prelude to package.yaml  
13: stack build.  
14: Edit Lib.hs to:

```haskell
{-# LANGUAGE OverloadedStrings #-}

module Lib
    ( someFunc
    ) where

import qualified Data.Text.IO as T
import ClassyPrelude

someFunc :: IO ()
someFunc = putStrLn "someFunc"

```

Note. When hover over ClassyPrelude I get the message

```haskell
Could not find module ‘ClassyPrelude’
It is not a module in the current program, or in any known package.not found

```

15: Add - aeson and -random to package.yaml

```haskell
dependencies:
- base >= 4.7 && < 5
- text
- filepath
- containers
- classy-prelude
- aeson 
- random

```

16: Edit Lib.hs to:

```haskell
{-# LANGUAGE OverloadedStrings #-}

module Lib
    ( someFunc
    ) where

import qualified Data.Text.IO as T
import ClassyPrelude
import System.Random  
import Data.Aeson

someFunc :: IO ()
someFunc = putStrLn "someFunc"

```

Same Errors:

```haskell
Could not find module ‘System.Random’
It is not a module in the current program, or in any known package.not found

Could not find module ‘Data.Aeson’
Perhaps you meant Data.Version (from base-4.14.3.0)not found

```

17: stack ls dependencies  
Output:  
OneTuple 0.3.1  
QuickCheck 2.14.2  
StateVar 1.2.2  
adjunctions 4.4.1  
aeson 2.0.3.0  
array 0.5.4.0  
assoc 1.0.2  
async 2.2.4  
attoparsec 0.14.4  
base 4.15.1.0  
base-compat 0.11.2  
base-compat-batteries 0.11.2  
base-orphans 0.8.6  
basic-prelude 0.7.0  
bifunctors 5.5.12  
binary 0.8.8.0  
bytestring 0.10.12.1  
chunked-data 0.3.1  
classy-prelude 1.5.0.2  
comonad 5.0.8  
containers 0.6.4.1  
contravariant 1.5.5  
data-default-class 0.1.2.0  
data-fix 0.3.2  
deepseq 1.4.5.0  
directory 1.3.6.2  
distributive 0.6.2.1  
dlist 1.0  
dlist-instances 0.1.1.1  
exceptions 0.10.4  
filepath 1.4.2.1  
free 5.1.9  
ghc-bignum 1.1  
ghc-boot-th 9.0.2  
ghc-prim 0.7.0  
hashable 1.3.5.0  
helloworld 0.1.0.0  
indexed-traversable 0.1.2  
indexed-traversable-instances 0.1.1  
integer-logarithms 1.0.3.1  
invariant 0.5.6  
kan-extensions 5.2.5  
keys 3.12.3  
mono-traversable 1.0.15.3  
mono-traversable-instances 0.1.1.0  
mtl 2.2.2  
mutable-containers 0.3.4  
pointed 5.0.4  
pretty 1.1.3.6  
primitive 0.7.3.0  
process 1.6.13.2  
profunctors 5.6.2  
random 1.2.1.1  
rts 1.0.2  
say 0.1.0.1  
scientific 0.3.7.0  
semialign 1.2.0.1  
semigroupoids 5.3.7  
semigroups 0.19.2  
split 0.2.3.4  
splitmix 0.1.0.4  
stm 2.5.0.0  
stm-chans 3.0.0.6  
strict 0.4.0.1  
tagged 0.8.6.1  
template-haskell 2.17.0.0  
text 1.2.5.0  
text-short 0.1.5  
th-abstraction 0.4.3.0  
these 1.1.1.1  
time 1.9.3  
time-compat 1.9.6.1  
transformers 0.5.6.2  
transformers-base 0.4.6  
transformers-compat 0.6.6  
unix 2.7.2.2  
unliftio 0.2.22.0  
unliftio-core 0.2.0.1  
unordered-containers 0.2.17.0  
uuid-types 1.0.5  
vector 0.12.3.1  
vector-algorithms 0.8.0.4  
vector-instances 3.4  
void 0.7.3  
witherable 0.4.2

Am I missing something???

Now, when I cd into src, run ghci and try to load Lib.hs I get this.  
1: cd src  
2: ghci  
3: :l Lib.hs (does not compile)

```haskell
GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help
Prelude> :l Lib.hs
[1 of 1] Compiling Lib ( Lib.hs, interpreted )

Lib.hs:8:1: error:
    Could not find module ‘ClassyPrelude’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
8 | import ClassyPrelude
  | ^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
Prelude> :l Lib.hs
[1 of 1] Compiling Lib ( Lib.hs, interpreted )

Lib.hs:9:1: error:
    Could not find module ‘System.Random’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
9 | import System.Random  
  | ^^^^^^^^^^^^^^^^^^^^

Lib.hs:10:1: error:
    Could not find module ‘Data.Aeson’
    Perhaps you meant Data.Version (from base-4.14.3.0)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
   |
10 | import Data.Aeson
   | ^^^^^^^^^^^^^^^^^
Failed, no modules loaded.

```

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [July 15, 2022, 9:35am UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/29 "2022-07-15T09:35:35Z")

</div>

I’d suggest checking out the HLS troubleshooting page:  
[https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html](https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html)

They have a section about problems with multi-component stack projects that might be relevant:  
[https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#problems-with-multi-component-support-using-stack](https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#problems-with-multi-component-support-using-stack)

---

<div class="post-metadata">

**Author:** ![1chb](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/1chb/32/1617_2.png) [@1chb](https://discourse.haskell.org/u/1chb)\
**Post date:** [July 15, 2022, 1:13pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/30 "2022-07-15T13:13:28Z")

</div>

Don’t cd into src. Start GHCI with stack ghci.

---

<div class="post-metadata">

**Author:** ![dalendisto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dalendisto/32/2434_2.png) [@dalendisto](https://discourse.haskell.org/u/dalendisto)\
**Post date:** [July 15, 2022, 2:00pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/31 "2022-07-15T14:00:49Z")

</div>

That’s what I usually do. I just wanted to see what happens…

---

<div class="post-metadata">

**Author:** ![1chb](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/1chb/32/1617_2.png) [@1chb](https://discourse.haskell.org/u/1chb)\
**Post date:** [July 15, 2022, 9:52pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/32 "2022-07-15T21:52:44Z")

</div>

I guess it starts the system installed `ghci`, or whatever `ghci` found in your path, without loading anything. From the `src` directory you can `: load` source files but I doubt it will find packages that are not installed globally.

---

<div class="post-metadata">

**Author:** ![dalendisto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dalendisto/32/2434_2.png) [@dalendisto](https://discourse.haskell.org/u/dalendisto)\
**Post date:** [July 16, 2022, 5:50am UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/33 "2022-07-16T05:50:33Z")

</div>

One thing I haven’t said yet but might be the missing piece. Before I reinstalled haskell with GHcup, I had a .ghc folder and some files in there. Also a file which listed all installed “packages/libraries”? ClassyPrelude was included in that list as well. So when i imported it, in some file in the src folder, I didn’t get the error message. That tells me that I somehow imported or installed it globally? Could that be the case? Thing is, I must have done it by accident, so I have no Idea how i did it 😣. Now when I do everything the way I described above, ClassyPrelude again gives me that “module not found” message.

---

<div class="post-metadata">

**Author:** ![cdepillabout](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/cdepillabout/32/1168_2.png) [@cdepillabout](https://discourse.haskell.org/u/cdepillabout)\
**Post date:** [July 16, 2022, 1:13pm UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/34 "2022-07-16T13:13:17Z")

</div>

Similar question here:

> [@"While building package haskell-gi-base-0.26.0 (scroll up to its section to see the error) using:"](http://discourse.haskell.org/t/while-building-package-haskell-gi-base-0-26-0-scroll-up-to-its-section-to-see-the-error-using/4786):
>
> Hi everyone. I was searching for some small but useful program to learn how Haskell functionalities are looks like in practice and learn something by modifying it. I found one of DistroTube tutorial: [https://www.youtube.com/watch?v=ViW-bcNQ6Lc&t=1291s](https://www.youtube.com/watch?v=ViW-bcNQ6Lc&t=1291s) I’ve cloned project from link below video but when i try to stack build it, i’ve got: haskell-gi-base \> configure haskell-gi-base \> Configuring haskell-gi-base-0.26.0... haskell-gi-base \> Cabal-simple\_mPHDZzAJ\_3.4.1.0\_ghc-9.0.2: The pkg-config…

---

<div class="post-metadata">

**Author:** ![tonyday567](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tonyday567/32/1073_2.png) [@tonyday567](https://discourse.haskell.org/u/tonyday567)\
**Post date:** [July 19, 2022, 7:56am UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/35 "2022-07-19T07:56:01Z")

</div>

Just reading through your steps and I don’t see anything amiss. It is a common bug where ghci has lost sight of the project. My guesses:

When you hover to see if stuff has worked, there hasn’t been a compilation that has worked yet. Try running ‘cabal build’ of ‘stack build’ and, on success, reboot the lsp service.

Use ‘cabal repl’ or ‘stack repl’ rather than ‘ghci’. I dont know why, but this helps.

If you start from the top, and get a successful build early, track builds external to hls with stack build or ghcid, then hls will be much happier.

---

<div class="post-metadata">

**Author:** ![dalendisto](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/dalendisto/32/2434_2.png) [@dalendisto](https://discourse.haskell.org/u/dalendisto)\
**Post date:** [July 19, 2022, 11:47am UTC](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761/36 "2022-07-19T11:47:23Z")

</div>

Hello Tony, I really appreciate your time and effort. I am now building an app with a TUI. The program compiles and runs no problems whatsoever. Still, the imports are all red and even after restarting the language server, it reverts back to red. I guess I will have to live with it for now. Generally I think trying to solve all these problems gives you a deeper understanding of how things work but it also takes away the focus on what you actually want to achieve. Tradeoffs, tradeoffs tradeoffs 😂. I still appreciate and respect all those people who develop such programs for us to have an easier life (in their spare time? I guess).

[Previous page](https://discourse.haskell.org/t/stack-failures-errors-frustrations/4761.md?page=1)
