haskellcabal

"constraint from non-upgradeable package requires installed instance" upon cabal build


I was building a project in which base^>=4.17.2.1 was in the dependencies. Cabal issued the following error message:

Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: mu-0.1.0.0 (user goal)
[__1] next goal: base (dependency of mu)
[__1] rejecting: base-4.19.0.0/installed-e537 (conflict: mu =>
base^>=4.17.2.1)
[__1] skipping: base-4.19.1.0, base-4.19.0.0, base-4.18.2.1, base-4.18.2.0,
base-4.18.1.0, base-4.18.0.0 (has the same characteristics that caused the
previous version to fail: excluded by constraint '^>=4.17.2.1' from 'mu')
[__1] rejecting: base-4.17.2.1, base-4.17.2.0, base-4.17.1.0, base-4.17.0.0,
base-4.16.4.0, base-4.16.3.0, base-4.16.2.0, base-4.16.1.0, base-4.16.0.0,
base-4.15.1.0, base-4.15.0.0, base-4.14.3.0, base-4.14.2.0, base-4.14.1.0,
base-4.14.0.0, base-4.13.0.0, base-4.12.0.0, base-4.11.1.0, base-4.11.0.0,
base-4.10.1.0, base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0,
base-4.8.1.0, base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0,
base-4.6.0.1, base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0,
base-4.4.0.0, base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1,
base-4.2.0.0, base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1
(constraint from non-upgradeable package requires installed instance)
[__1] fail (backjumping, conflict set: base, mu)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, mu

Apparently Cabal has already found the required base-4.17.2.1 as in the fourth [__1], however rejected due to "constraint from non-upgradeable package requires installed instance".

Here's another instance where the build has been frozen. Again Cabal has successfully found the required base-4.17.2.1 but then immediately rejected due to the very same reason.

Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: mu-0.1.0.0 (user goal)
[__1] next goal: base (dependency of mu)
[__1] rejecting: base-4.19.0.0/installed-e537, base-4.19.1.0, base-4.19.0.0,
base-4.18.2.1, base-4.18.2.0, base-4.18.1.0, base-4.18.0.0 (constraint from
project config /Users/futar/Documents/code-projs/mu/cabal.project.freeze
requires ==4.17.2.1)
[__1] rejecting: base-4.17.2.1 (constraint from non-upgradeable package
requires installed instance)
[__1] rejecting: base-4.17.2.0, base-4.17.1.0, base-4.17.0.0, base-4.16.4.0,
base-4.16.3.0, base-4.16.2.0, base-4.16.1.0, base-4.16.0.0, base-4.15.1.0,
base-4.15.0.0, base-4.14.3.0, base-4.14.2.0, base-4.14.1.0, base-4.14.0.0,
base-4.13.0.0, base-4.12.0.0, base-4.11.1.0, base-4.11.0.0, base-4.10.1.0,
base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0,
base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1,
base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0,
base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0,
base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from
project config /Users/futar/Documents/code-projs/mu/cabal.project.freeze
requires ==4.17.2.1)
[__1] fail (backjumping, conflict set: base, mu)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, mu

But what is a "non-upgradeable package" and which package is it? Also an installed instance of what is required? If it's base-4.17.2.1, then why isn't it installed by Cabal just like any other packages in the dependencies? I'm so confusion.


Solution

  • If you run ghcup list, you'll see that the GHC version associated with base-4.7.2.1 is GHC 9.4.8. Make sure it's installed:

    $ ghcup install ghc 9.4.8
    

    and then select it and rebuild:

    $ ghcup set ghc 9.4.8
    $ cabal build
    

    As further explanation, Cabal uses the currently selected version of GHC to build your project. It looks like you probably have GHC 9.8.1 selected, since the currently installed base package is base-4.19.0.0.

    The error message results because this package is tied to the current GHC version and so can't be downgraded to base-4.17.2.1. (Here, "non-upgradeable" is misleading; newer versions of Cabal have replaced this error message with "non-reinstallable".)

    (Note that Stack works differently, so stack build always builds with the package-specified GHC version, and you won't need to use ghcup set.)