Flags with primitive types getting rejected as undefined [using Parcel]

I suspect this issue is Parcel specific, but not certain and could not find any forum for Parcel to post this anyway.

Used elm-app-gen to bootstrap my project.

When I try initializing my app with flags like so:

    node: document.getElementById("app")
    , flags: 1

And defining them in Main like so:

main : Program Int Model Msg
init : Int -> Url -> Nav.Key -> ( Model, Cmd Msg )

When I try to run the program with parcel public/index.html the flags are rejected as undefined:

Problem with the flags given to your Elm program on initialization.

Problem with the given value:


Expecting an INT

If I change my flags value to a String in js though:

    node: document.getElementById("app")
    , flags: "test"

Then the error does seem to register the value as defined, but incompatible:

Problem with the given value:


Expecting an INT

If I then change the types in Elm to String as well though:

main : Program String Model Msg
init : String -> Url -> Nav.Key -> ( Model, Cmd Msg )

Then the error goes back to saying the value is undefined…

Problem with the given value:


Expecting a STRING

Anyone had this issue before or have any idea why it might be doing this?
Any help would be most appreciated!

For a brief moment I was able to see your error but now I cannot reproduce it anymore.

The idea is that Browser.application always mounts on the body and as such there should not be a node argument to Elm.Main.init, only the flags.

Once I removed the node argument, the app worked as expected. When I put the node argument back, the app still works… so… I don’t know what to say about the actual cause.

I have tried creating a new app from scratch and implementing the same changes but I could not reproduce the error.

Anyways… I do not think this error is related to parcel. It might be one of the other tools that are installed by elm-app-gen.

1 Like

I found the issue. Elm.Main.init() was being called twice by accident… :expressionless:

Thanks for sharing the insight about the node not being needed in the init args @pdamoc Guess it was an oversight to include that in elm-app-gen?


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.