Module X appears in multiple packages

I am writing a short Turtle script in Haskell, running it with Stack:

#!/usr/bin/env stack
-- stack --resolver lts-19.6 script
                                    
{-# LANGUAGE OverloadedStrings #-}  
                                    
import Turtle                       
import Data.Text 

But as soon I added the “Data.Text” import I get this error:

Module Data.Text appears in multiple packages: 
relude text

Not a typo, it really says “relude”.

How can I resolve it?

You can fix this by explicitly specifying which packages you want to use:

#!/usr/bin/env stack
-- stack --resolver lts-19.6 script --package text --package turtle
                                    
{-# LANGUAGE OverloadedStrings #-}  
                                    
import Turtle                       
import Data.Text 

I think by default it exposes all packages in the snapshot, so then there indeed may be multiple packages that provide the same module, which stack cannot resolve by itself.

An alternative solution would be to use PackageImports:

#!/usr/bin/env stack
-- stack --resolver lts-19.6 script
                                    
{-# LANGUAGE OverloadedStrings, PackageImports #-}  
                                    
import Turtle                       
import "text" Data.Text 

Do take a look at the documentation for best practices:

https://docs.haskellstack.org/en/stable/scripts/

Leave a Comment