3

While trying to debug a different question, I installed a package that seems to conflict with some of my other installed packages.

I ran

$ stack install regex-pcre-text
regex-pcre-builtin-0.94.4.8.8.35: configure
regex-tdfa-1.2.3.1: download
regex-pcre-builtin-0.94.4.8.8.35: build
regex-tdfa-1.2.3.1: configure
regex-tdfa-1.2.3.1: build
regex-pcre-builtin-0.94.4.8.8.35: copy/register
regex-tdfa-1.2.3.1: copy/register
regex-tdfa-text-1.0.0.3: download    
regex-tdfa-text-1.0.0.3: configure   
regex-tdfa-text-1.0.0.3: build       
regex-tdfa-text-1.0.0.3: copy/register
regex-pcre-text-0.94.0.1: download    
regex-pcre-text-0.94.0.1: configure   
regex-pcre-text-0.94.0.1: build       
regex-pcre-text-0.94.0.1: copy/register
Completed 4 action(s).                

I can no longer simply import

Text.Regex.PCRE

When I try, I now see:

$ stack ghci
Prelude> :set -XOverloadedStrings
Prelude> import Text.Regex.PCRE

Yields

<no location info>: error:
    Ambiguous module name ‘Text.Regex.PCRE’:
      it was found in multiple packages:
      regex-pcre-0.94.4 regex-pcre-builtin-0.94.4.8.8.35

I would like to revert my installation to the earlier state such that code on my machine that imports Text.Regex.PCRE without qualification continues to work as it used to.

However, it looks like stack does not have a clear uninstall:

$ stack uninstall regex-pcre-text

Error: stack does not manage installations in global locations. The only global mutation stack performs is executable copying. For the default executable destination, please run stack path --local-bin

I hesitate to simply run this stack path --local-bin because I don't know what it's going to do, or whether it can be reversed (which was my error in installing the above package in the first place). What is the right fix for my import problem?

Update 1

I tried suggestions here:

$ ghc-pkg unregister regex-pcre-text
ghc-pkg: cannot find package regex-pcre-text

$ stack exec ghc-pkg unregister regex-pcre-text
ignoring (possibly broken) abi-depends field for packages
Mittenchops
  • 18,633
  • 33
  • 128
  • 246
  • In general, you can use [`PackageImports`](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#extension-PackageImports) for things like this. – DarthFennec Apr 16 '19 at 21:26
  • 1
    Related: https://stackoverflow.com/questions/38636436/how-to-uninstall-a-haskell-package-installed-with-stack – DarthFennec Apr 16 '19 at 21:37
  • 2
    In my experience, you're not really supposed to be using stack to install things globally. It just leads to headaches like this every single time. Instead, you can create a sandbox environment for your project directory, and all dependencies (including your ghc binary) will be managed independently inside that directory. [resource](https://docs.haskellstack.org/en/stable/README/#quick-start-guide) – DarthFennec Apr 16 '19 at 21:43
  • In your specific case here, as far as I can tell, [regex-pcre](http://hackage.haskell.org/package/regex-pcre) and [regex-pcre-builtin](http://hackage.haskell.org/package/regex-pcre-builtin) are different builds of the same package, so they should be interchangeable. Since `regex-pcre-text` requires `regex-pcre-builtin`, as long as none of your dependencies require `regex-pcre` I would remove that. Then when you import `Text.Regex.PCRE`, it'll use `regex-pcre-builtin`, which should work as expected. – DarthFennec Apr 16 '19 at 21:49
  • Simply `import Text.Regex.PCRE` produces `:1:1: error: Ambiguous module name ‘Text.Regex.PCRE’: it was found in multiple packages: regex-pcre-0.94.4 regex-pcre-builtin-0.94.4.8.8.35` – Mittenchops Apr 16 '19 at 21:51
  • Yes, that means `Text.Regex.PCRE` was found in both `regex-pcre` (which I assume you had installed earlier) and `regex-pcre-builtin` (which was installed as a dependency of `regex-pcre-text`, and should be equivalent to `regex-pcre` as far as I can tell). – DarthFennec Apr 16 '19 at 21:59
  • In response to your Update 1, `ghc-pkg unregister` takes a package id, which can be retrieved by doing `ghc-pkg field regex-pcre-text id` (according to the comments in the linked answer). Although I get the feeling that doing this won't unregister any of the dependencies, so you'd have to do those manually. Or, alternatively, you can unregister `regex-pcre` since `regex-pcre-builtin` appears to be the same interface. – DarthFennec Apr 16 '19 at 22:03

1 Answers1

4

The issue is that regexp-pcre-text installed its dependency regex-pcre-builtin which caused the conflict. You want to run both of the following commands in the global project (i.e., outside of any specific project directory):

$ stack exec ghc-pkg unregister regex-pcre-text
$ stack exec ghc-pkg unregister regex-pcre-builtin

You already ran the first, and I suspect it completed successfully, despite the warning message about the abi-depends fields, so you just need to run the second.

(These could be combined into a single command:

$ stack exec ghc-pkg unregister regex-pcre-text regex-pcre-builtin

but given you already removed the first package, I believe this would fail with a message that regex-pcre-text wasn't found.)

The solution mentioned by @DarthFennec is to use the PackageImports extension to resolve the conflict. From GHCi, it would look like this, to use the module from the regex-pcre package even with both packages installed:

Prelude> :set -XPackageImports
Prelude> import "regex-pcre" Text.Regex.PCRE
Prelude Text.Regex.PCRE>
K. A. Buhr
  • 45,621
  • 3
  • 45
  • 71
  • Thanks, this was exactly it---I both had to run it outside of a project directory and it likely succeeded even though it displayed an error message, which confused me. Doing this fixed my problem. – Mittenchops Apr 17 '19 at 15:25