4

I have

mainLogger.hs
Logger.hs

in my local directory where the mainLogger.hs reference the Logger module.

When in stack ghci I :load mainLogger.hs I get the following error message :

mainLogger.hs:6:18:
    Could not find module ‘Logger’
    It is not a module in the current program, or in any known package.

However if I can compile stack exec -- ghc mainLogger.hs and run stack runghc mainLogger2.hs or have stack exec -- ghci load the module correctly.

Anyone knows what is preventing stack ghci from locating module in the local directory ?

ps : I am not using any cabal file or stack.yaml file in this directory, so it falls back onto my global stack.yaml config

nicolas
  • 9,549
  • 3
  • 39
  • 83
  • @Carsten I guess. trying this now. my emacs by default launched stack ghci that's why I am looking into this – nicolas May 27 '16 at 09:23
  • 1
    I had to test it to make sure but you should be able to load both if you just do `:load Logger.h mainLogger.hs` - I don't know if you can get GHCi to look for the missing module in the current folder if you have no cabal file (I usually just create one) – Random Dev May 27 '16 at 09:27
  • @Carsten yes ! it works. I tried loading one then the other (failed), but giving them both at the same time does work . can you put this as an answer ? – nicolas May 27 '16 at 09:31
  • now unfortunately, emacs does them one at a time, but that's another issue – nicolas May 27 '16 at 09:31
  • 1
    yes - based on the description I would have thought that it would look for a correctly named file in the current path (you can see that the path is right with `:show paths`) but nope sadly not – Random Dev May 27 '16 at 09:34
  • @Carsten the path look right indeed. I dont know why it would load under ghci but not under stack ghci. the only difference seems that paths are relative in `ghci` and absolute in `stack ghci`.. is it a bug ? – nicolas May 27 '16 at 09:49

2 Answers2

4

You should be able to load both if you do it at the same time:

:load Logger.hs mainLogger.hs 

I don't know if you can get GHCi to look for the missing module in the current folder if you have no cabal file but if you create/initialize one this is not necessary.

Sibi
  • 47,472
  • 16
  • 95
  • 163
Random Dev
  • 51,810
  • 9
  • 92
  • 119
2

This issue should now be fixed in the latest version of stack. It seems that when a module imported a local module, stack wasn't including the local directory in its module search path. In the latest 1.5.1. version of stack, this has been fixed - so you should be able to just type

stack ghci mainLogger.hs