I'm using Giraffe and trying to integrate Elmish.Bridge. I get the following error:
error FS0892: This declaration opens the module 'Elmish.Bridge.Giraffe', which is marked as 'RequireQualifiedAccess'. Adjust your code to use qualified references to the elements of the module instead, e.g. 'List.map' instead of 'map'. This change will ensure that your code is robust as new constructs are added to libraries.
if I open the modules in the following order:
open Elmish.Bridge
open Giraffe
but if I swap the order then the error goes away.
open Giraffe
open Elmish.Bridge
Can someone please explain why this happens and how best to resolve it?
It's a naming conflict.
When you open Elmish.Bridge
, this brings into scope the module Elmish.Bridge.Giraffe
, and it becomes addressable by the name Giraffe
. This is exactly what is supposed to happen when you open a module: all its content becomes "in scope".
The problem is that this conflicts with another module named Giraffe
, coming from a different library.
When such naming conflict arises, F# gives preference to names from the most recently opened modules. Therefore, when you write open Giraffe
, the compiler takes it to mean open Elmish.Bridge.Giraffe
. And since that module requires qualified access (i.e. cannot be open
ed), the compiler issues the relevant error.
When you put open Giraffe
before open Elmish.Bridge
, the compiler takes it to mean the module Giraffe
, not Elmish.Bridge.Giraffe
, because the latter is not yet in scope at that point. The global module Giraffe
can be opened, so you get no error.
Besides changing the order of open
lines, you can work around the conflict by explicitly specifying that you mean the "global" module Giraffe
, not Elmish.Bridge.Giraffe
, by using prefix global.
, like this:
open Elmish.Bridge
open global.Giraffe