"Could not find module" after spago install — why doesn't the new package resolve?
0 reputation · 30 May 2024, 19:47 UTC
0 reputation · 30 May 2024, 19:47 UTC
I'm setting up a repeatable PureScript development environment with Spago (PureScript compiler 0.15.x, recent Spago) and keep hitting a module resolution failure I don't fully understand.
After running spago install purescript-aff, importing Effect.Aff in a source file and running spago build fails with an error along the lines of Could not find module Effect.Aff. The package appears to be fetched, yet the compiler cannot resolve it during module lookup.
My understanding is that the compiler resolves modules from src plus the dependency sources Spago materializes, and that spago.dhall controls which packages are actually included in the build. What I can't pin down is the exact contract between spago install and the dependencies list in spago.dhall: does installing a package always update the manifest, or can the two drift apart so that a package is downloaded but excluded from compilation?
Specifically:
spago install leave spago.dhall unchanged, causing this error?32275 reputation · 31 May 2024, 06:53 UTC
With PureScript 0.15.x and a recent Spago release, spago install normally updates the manifest so the package is on the compiler search path. The "Could not find module Effect.Aff" you see after spago install purescript-aff is therefore not the normal "install downloads but manifest stays stale" drift. The most common cause in this setup is a name / manifest file mismatch.
src. If a package is not listed as a dependency, its modules are not on the search path.spago.yaml with a lock file spago.lock. Legacy dhall-based Spago used spago.dhall and packages.dhall as the package set.spago install in both generations updates the manifest dependencies. It does not leave the manifest unchanged by design.aff, not purescript-aff. The module you import is Effect.Aff from the package aff.You mention spago.dhall while also stating PureScript 0.15.x and "recent Spago". Recent Spago for 0.15.x is registry-based and uses spago.yaml, not spago.dhall. If a spago.dhall file is present, Spago will ignore it and use spago.yaml, so an install that appears to succeed may update the wrong file.
Separately, running spago install purescript-aff uses the npm-style name. Spago expects the short name aff. An install with the wrong name can fetch nothing useful or create a dependency entry that does not resolve to the module you import.
spago --version
If the version is 0.93 or newer, the project uses spago.yaml + spago.lock. If you still have spago.dhall, you are on legacy Spago which is not the supported pairing for purs 0.15.x.ls spago.yaml spago.dhall
Open the file that exists and inspect the dependencies section.grep -n "aff" spago.yaml
You should see an entry like aff under dependencies. If you see purescript-aff, remove it and add the correct short name.spago install aff
This updates the manifest and lock file together.spago build
The module Effect.Aff should now resolve.Commit the manifest and lock file that your Spago generation uses: spago.yaml and spago.lock for registry Spago, or spago.dhall and packages.dhall for legacy. CI should run spago build which respects those committed files. Do not rely on ad-hoc spago install runs in CI.
One missing diagnostic that changes the recommendation: which manifest file your project actually uses and the output of spago --version. With that I can confirm whether you are on legacy dhall Spago or registry Spago and give the exact edit path.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.