Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

ghc-mod with stack: Could not find module ‘.... #668

Closed
deflexor opened this issue Oct 23, 2015 · 9 comments
Closed

ghc-mod with stack: Could not find module ‘.... #668

deflexor opened this issue Oct 23, 2015 · 9 comments

Comments

@deflexor
Copy link

How to reproduce:

Create new project with stack tool, then open source file in emacs and add line like:
import System.Random
Then open repl with C-c C-l and it will offer to add package random to cabal file and restart ghci. After this done repl starts to work fine, but the import line in source buffer is still higlighted with red and if i run from terminal ghc-mod check app/Main.hs then get this error:

app/Main.hs:5:12:Could not find module ‘System.Random’It is a member of the hidden package ‘random-1.1@rando_1z8Ujelqc6aKgvPnbRUKkP’.Perhaps you need to add ‘random’ to the build-depends in your .cabal file.Use -v to see a list of the files searched for.
@meditans
Copy link
Contributor

You have to delete .stack-works/dist/x86_64-linux/Cabal-1.22.4.0/setup-config.ghc-mod.* (or the equivalent).

I know, an option to do it automatically would be nice, sit tight for the next releases :)

@nrolland
Copy link
Contributor

@meditans can you provide some context for this ? what's the purpose of this file etc.. if you know of course

@DanielG
Copy link
Owner

DanielG commented Oct 24, 2015

It's a bunch of caches that we generate from Cabal's LocalBuildInfo stuff.

@DanielG
Copy link
Owner

DanielG commented Oct 24, 2015

See https://github.com/kazu-yamamoto/ghc-mod/blob/master/Language/Haskell/GhcMod/PathsAndFiles.hs#L228S

If you look for references to all those binders you'll find the places where the caches are being generated. Presumably they're not being invalidated properly.

@DanielG
Copy link
Owner

DanielG commented Nov 26, 2015

I have a feeling this should have been fixed by a combination of 8568a67 and a12a7fa. @deflexor can you try using master for a while to see if it happens again?

AFAIK the problem was that ghc-modi's in-memory cache was not being invalidated but rather written over the external cache files unconditionally. This lead to very strange behavior where ghc-mod debug on the command line would show the problem and as soon as you clean the caches and do ghc-mod debug again it would be fixed. But if you kept Emacs running in the mean time ghc-modi would just overwrite the external caches with it's wrong in-memory cache as soon as you run any command.

@DanielG
Copy link
Owner

DanielG commented Nov 26, 2015

@deflexor Oh and don't forget to remove all the caches, we're using binary instead of cereal now so the format is different. Once we release the next version this will be fine as the caching code checks the ghc-mod version but for now it'll appear the same.

Just removing dist/ or .stack-work/ is the easiest way to accomplish that btw.

@deflexor
Copy link
Author

Checked it with github version of ghc-mod and this behaviour is not repeating anymore. Thanks.

@muhuk
Copy link

muhuk commented Jun 18, 2016

I am experiencing this issue with:

stack-1.0.0
ghc-mod-5.5.0.0
cabal-helper-0.6.3.1

Deleting files (running rm .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/setup-config.ghc-mod.* on my project root) fixes the problem temporarily, but then these two files get created again:

.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/setup-config.ghc-mod.cabal-components  
.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/setup-config.ghc-mod.resolved-components

I see the error for packages defined for test build, but in lib files. For example src/Foo.hs would report that it Could not find module 'Test.Hspec'. (I am of course not importing Hspec within Foo.)

Everything works when I run stack commands directly.

@freckletonj
Copy link

I had the same problem haskell/haskell-ide-engine#1006

cleaning up worked for me:

rm -r .stack-work
stack test # I think I needed to run this before ghcmod could pick up the test targets
emacs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants