On Windows 10, if I do stack new SomeFunc; cd SomeFunc; stack setup; stack build; and then stack ghci an error is reported which suggests to me that perhaps a main-is path with a space is not being handled correctly.
With no space in the path (eg Users folder jsmith), the GHCi startup output of stack ghci includes:
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Lib ( C:\Users\jsmith\Documents\Code\Haskell\SomeFunc\src\Lib.hs, interpreted )
Ok, modules loaded: Lib.
[2 of 2] Compiling Main ( C:\Users\jsmith\Documents\Haskell\SomeFunc\app\Main.hs, interpreted )
Ok, modules loaded: Lib, Main.
*Main Lib>
With a space in the path (eg Users folder Jane Smith), the same part of that output has:
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Lib ( C:\Users\Jane Smith\Documents\Code\Haskell\SomeFunc\src\Lib.hs, interpreted )
Ok, modules loaded: Lib.
target `C:\Users\Jane' is not a module name or a source file
*Lib Lib>
Can you post the output of stack --version?
Yes, it is: Version 1.1.2, Git revision c6dac65e3174dea79df54ce6d56f3e98bc060ecc (3647 commits) x86_64 hpack-0.14.0.
I reproduce this issue on Linux with a space in my file names:
bash-3.2$ stack --version
Version 1.1.3, Git revision 7f7f1a5f67f4ecdd1f3009495f1ff101dd38047e (dirty) (3713 commits) x86_64 hpack-0.14.0
bash-3.2$ stack ghci .
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Using main module: 1. Package `foobar' component exe:foobar-exe with main-is file: /Users/chris/foo bar/foobar/app/Main.hs
Configuring GHCi with the following packages: foobar
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
package flags have changed, resetting and loading new packages...
[1 of 1] Compiling Lib ( /Users/chris/foo bar/foobar/src/Lib.hs, /Users/chris/foo bar/foobar/.stack-work/odir/Lib.o ) [flags changed]
Ok, modules loaded: Lib.
target ‘/Users/chris/foo’ is not a module name or a source file
Prelude Lib> :q
Leaving GHCi.
Probably not a surprise, but I've seen the same thing on Mac OS X
This might just be a quoting issue in some kind of ghci loading script:
λ> :load /home/simon/test/bli bla/repro/src/Lib.hs
target `/home/simon/test/bli' is not a module name or a source file
λ> :load "/home/simon/test/bli bla/repro/src/Lib.hs"
[1 of 1] Compiling Lib ( /home/simon/test/bli bla/repro/src/Lib.hs, interpreted )
Ok, modules loaded: Lib.
(0.02 secs, 4096288 bytes)
Good catch! I hadn't considered that yet!
I think you've nailed it, @sjakobi. Applying the fix now.
@mpilgrem @WeeBull @sjakobi @sjakobi @VitorCBSB Pushed a fix, can you update your stack from master and try again?
Thanks for your work, Chris. Unfortunately it didn't seem to work for me, my issue (the one with intero) is still happening.
The funny thing is that calling the stack ghci command on my projects never actually failed to work for me for some reason.
C:\Users\Vitor Coimbra>stack --version
Version 1.1.3, Git revision a9a3dacdfa7b5b42278c6b0677aa142f4d39c46b (3729 commits) x86_64 hpack-0.14.0
Works for me on Ubuntu 14.04 with stack ghci!
It did not work for me on Windows 10. stack --version is:
Version 1.1.3, Git revision 823a677230b7cfadaac76fca22ecedd270b35576 x86_64 hpack-0.14.0
The relevant part of the output from stack ghci is now:
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Lib ( C:\Users\Jane Smith\Documents\Code\Haskell\SomeFunc\src\Lib.hs, interpreted )
Ok, modules loaded: Lib.
Couldn't read "\"C:\\Users\\Jane Smith\\Documents\\Code\\Haskell\\SomeFunc\\app\\Main.hs\""as String
*Lib Lib>
I'm trying it out on a Windows VM.
Okay, I reproduce on Windows:
Couldn't read "\"C:\Users\IEUser\foo bar\foo\appMain.hs\""as String
Well, that's funny. GHCi expects an escaped string:
This is what stack is passing to ghci presently:
*Lib Lib> :!cat C:\Users\IEUser\AppData\Local\Temp\ghci2588\ghci-script
:add Lib
:add "C:\Users\IEUser\foo bar\foo\app\Main.hs"
:module + Lib
*Lib Lib> :add "C:\Users\IEUser\foo bar\foo\app\Main.hs"
Couldn't read "\"C:\\Users\\IEUser\\foo bar\\foo\\app\\Main.hs\""as String
But this works:
*Lib Lib> :add "C:\\Users\\IEUser\\foo bar\\foo\\app\\Main.hs"
[2 of 2] Compiling Main ( C:\Users\IEUser\foo bar\foo\app\Main.hs, interpreted )
Ok, modules loaded: Lib, Main.
Seems like my quoteFileName function was wrong. I'll make it just be show.
Okay, that fixed it!
Closing, @mpilgrem re-open if you encounter it again. 👍
I am having the same problem using stack version 1.6.3, ghc 8.2.2: spaces in filenames lead to ghci complaining about "is not a module name or a source file".
I now hotfixed my Emacs Intero implementation to put " quotes around the filename, and that resolved it.
Should Intero by default put quotes around paths when passing them to ghc, or should ghc be able to deal with paths containing spaces even when they are not quoted?