Haskell GHC "Could not find module" in CI
GHC tried to import a module and no package in the current build provides it. Either the package that exposes it is not listed in build-depends, or a local module is not listed in the cabal/package file.
What this error means
A build fails with "Could not find module 'X'", often adding "Perhaps you meant ..." or "It is not a module in the current program, or in any known package."
app/Main.hs:3:1: error:
Could not find module 'Data.Text'
Perhaps you need to add 'text' to the build-depends in your .cabal file.
Use -v (or `:set -v` in ghci) to see a list of the files searched for.Common causes
The providing package is not in build-depends
GHC only sees modules from packages listed under build-depends; omitting the package means its modules are not in scope.
A local module is not listed in the cabal file
A project module exists on disk but is not under other-modules or exposed-modules, so the build does not include it.
How to fix it
Add the package to build-depends
- Read which module GHC could not find and which package provides it.
- Add that package to
build-dependsin the cabal file. - Rebuild so the module is in scope.
executable app
main-is: Main.hs
build-depends: base, textList the local module in the cabal file
If the missing module is local, add it to other-modules (or exposed-modules for a library) so the build compiles it.
library
exposed-modules: MyApp.Config
other-modules: MyApp.InternalHow to prevent it
- Keep build-depends in sync with the imports your code uses.
- List every local module under other-modules or exposed-modules.
- Build cleanly from a fresh checkout to catch unlisted modules.