elm-lang / elm-platform

Bundle of all core development tools for Elm
BSD 3-Clause "New" or "Revised" License
762 stars 125 forks source link

_elm_lang$core$Json_Decode$andThen undefined when using Elm worker #184

Closed sanichi closed 8 years ago

sanichi commented 8 years ago

I have an app which uses Elm 0.18 as the "brain" for something else, so I'm using Elm.Main.worker() in my JavaScript and Platform.program in Main.elm. The Elm program compiles but when the code loads in the browser I get a JavaScript error: _elm_lang$core$Json_Decode$andThen undefined.

I found two workarounds for the problem which should be useful clues as to what's happening.

Workaround 1 Import Html even though it isn't explicitly used:

The problem disappears if I add one additional line into Main.elm: import Html even though I don't explicitly use that module.

Workaround 2 Change to Html.program with a dummy view:

If I modify the app to use Html.program instead of Platform.program, add a dummy view function, add a dummy div node for the app to embed in and modify the JavaScript to Elm.Main.embed(node) then the problem also disappears.

In both workarounds when I inspect the compiled JavaScript I can see the variable _elm_lang$core$Json_Decode$andThen being defined (and also many other similar variables) but otherwise these lines are missing.

Here is one of the lines which appear only in the workaround versions:

var _elm_lang$core$Json_Decode$andThen = _elm_lang$core$Native_Json.andThen;
process-bot commented 8 years ago

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

evancz commented 8 years ago

This seems the same as https://github.com/elm-lang/core/issues/703

Do you agree? If so, let's close it here and keep tracking it over there.

sanichi commented 8 years ago

Indeed it does, I'll close. Thanks.