Compiler: SSCCE: `elm: Map.!: given key is not an element in the map` when using --debug

Created on 18 Sep 2018  ·  13Comments  ·  Source: elm/compiler

Hi,

I converted a large (80k lines) SPA of elm code to 0.19. The compile time went down to 1-2s from previously ~3-4 mins, so cheers to that!

I should prefix that this error only occurs when using --debug.

I get the "Success! Compiled 275 modules." message, followed by an error. See screenshot below:

screen shot 2018-09-18 at 10 12 50 am

After moving things/commenting out things, I was left with what I believed to be the root problem.

The error was a bit tricky to track down as it only happens when the package is installed from package.elm-lang.org. When the package is added on disk and added to source-directories, everything works fine.

For this very reason I had to create and publish the following package: https://package.elm-lang.org/packages/ryan-senn/elm-compiler-error-sscce/latest/

Please feel free to delete when deemed appropriate. It is the only way to reproduce the error.

Here is an app with the minimal amount of code to reproduce the error: https://github.com/ryan-senn/elm-compiler-error-remote.

You'll notice that there are two Type Msg in src/Main.elm, one which works, one which produces the error. Comment out one or the other to toggle between what works/breaks.

Simply run elm make src/Main.elm --debug to see the result.

To make things interesting, here is the exact same app, except that MsgSscce is not a dependency, but instead the files are on disk and the directory is added to source-directories.

https://github.com/ryan-senn/elm-compiler-error-local

As you can see, now it always works, regardless of which Msg you uncomment.

OS: macOs High Sierra 10.13.4

Please let me now if I can help further.

Most helpful comment

Putting an array in the message type always gets me the Map.!error when compiling with --debug
```module Main exposing (main)

import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Array exposing (..)

type alias Model =
{ count : Int }

initialModel : Model
initialModel =
{ count = 0 }

type Msg
= Msg1 (Array Int)

update : Msg -> Model -> Model
update msg model =
case msg of
Msg1 arr ->
model

view : Model -> Html Msg
view model =
div []
[]

main : Program () Model Msg
main =
Browser.sandbox
{ init = initialModel
, view = view
, update = update
}
```

All 13 comments

I have a slightly different SCCE here: https://github.com/magopian/repro-issue/blob/60138e3d1303eff55af78cc207e6921c1d982e80/src/Main.elm#L31

The line that is linked is the single line that when added causes the exact same error message:

11:34 $ elm make --debug src/Main.elm 
Success! Compiled 1 module.                                          
elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries/containers/Data/Map/Internal.hs:603:17 in containers-0.5.10.2:Data.Map.Internal

I can confirm that if I move the elm/http dependency from the indirect to the direct entry in the elm.json file then everything works as expected (see the commit which makes it work).

I guess it's "encapsulating" a message (from an indirect dependency?) that produces the issue. In my case, it's having an Http.Error encapsulated in a Kinto.Error.

In our 35k LOC app, moving the dependencies did NOT fix the problem

In our 35k LOC app, moving the dependencies did NOT fix the problem

Same for us

> elm make src/elm/App.elm --output=public/main.js --debug

screen shot 2018-09-30 at 21 26 20

I've also had the same thing using the --debug flag, I was converting an ~11K LOC app to use elm-css and started getting these errors, works fine without the flag

Also on macOS high Sierra 10.13.4

I have this error without using the debug flag.

https://github.com/elm/compiler/issues/1817#issuecomment-426511157

Ubuntu 16.04

Putting an array in the message type always gets me the Map.!error when compiling with --debug
```module Main exposing (main)

import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Array exposing (..)

type alias Model =
{ count : Int }

initialModel : Model
initialModel =
{ count = 0 }

type Msg
= Msg1 (Array Int)

update : Msg -> Model -> Model
update msg model =
case msg of
Msg1 arr ->
model

view : Model -> Html Msg
view model =
div []
[]

main : Program () Model Msg
main =
Browser.sandbox
{ init = initialModel
, view = view
, update = update
}
```

we have the same problem, only with the debug flag. We have no Array types in the messages....

I experience the same problem (only with the debug flag) when using https://github.com/CurrySoftware/elm-datepicker.

I'm seeing the same error with elm 0.19 when I add a Msg that takes an Array. Converting it to a List for the message and then back to an Array in the rest of the program seems to be a workaround. The Array in Msg bug was present even when the Array was within a record.

I'm using "create-elm-app". The start command does not work and the build command works so it looks like this is the same issue, relating to the debug flag.

This feels bad because there's no option to remove the debug flag in create-elm-app generated applications and people using create-elm-app are more likely to have limited experience with Elm. It's taken me a fair amount of Googling and trial and error to work this out.

Interestingly, I have a different line number to OP and a different containers version.

Failed to compile.

./src/Main.elm

Success! Compiled 1 module.                                          
elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at ./Data/Map/Internal.hs:610:17 in containers-0.5.11.0-K2TDqgYtGUcKxAY1UqVZ3R:Data.Map.Internal

@adamnfish you can set ELM_DEBUGGER=false in your environment variables to disable the Elm debugger when using create-elm-app

Here's another SSCCE:

module Main exposing (main)

import Array exposing (Array)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Set.Any exposing (AnySet)


type
    Msg
    --= Click (AnySet String String)
    --= Click (Array String)
    = Click String


update : Msg -> () -> ()
update msg model =
    case msg of
        Click _ ->
            ()


view : () -> Html Msg
view model =
    let
        value =
            --Set.Any.fromList identity []
            --Array.empty
            "ok"
    in
    div []
        [ button [ onClick <| Click value ] [ text "click me" ]
        ]


main : Program () () Msg
main =
    Browser.sandbox
        { init = ()
        , view = view
        , update = update
        }

Both the AnySet and Array Msgs will cause:

Success! Compiled 1 module.                                          
elm: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at ./Data/Map/Internal.hs:610:17 in containers-0.5.11.0-K2TDqgYtGUcKxAY1UqVZ3R:Data.Map.Internal

when using elm make src/Main.elm --debug.

Related: https://github.com/elm/compiler/issues/1817

Just FYI, I've had this problem when using a package selectize, but then I've copied its sources in my project (instead of using a package manager) and --debug build works again

Moved to meta issue in https://github.com/elm/compiler/issues/1851 so I can track everything easier.

To the people who found a small SSCCE, please open your own issue with an SSCCE of your case. Adding on to an existing issues with examples that are maybe the same root problem (maybe not!) makes the thread really hard to work with. Just open a fresh issue describing your case on its own.

Was this page helpful?
0 / 5 - 0 ratings