elm-lang / elm-make

A build tool for Elm projects
BSD 3-Clause "New" or "Revised" License
175 stars 45 forks source link

[0.18] Json.Decode used but not included in compiled JS #134

Closed pauldijou closed 7 years ago

pauldijou commented 7 years ago

I hope I'm not missing something but I created a really small Elm program with flags. It looks like the resulting JS code is using _elm_lang$core$Json_Decode to decode all flags. But my code does not import Json.Decode, so it's not included in the compiled JS file, resulting in a runtime exception: ReferenceError: _elm_lang$core$Json_Decode$andThen is not defined

I'm pretty sure I didn't have the problem in Elm 0.17

Elm code

module Bug exposing (main)

type Msg = Noop
type alias Model = Float
type alias Flags = { start: Float }

main: Program Flags Model Msg
main =
  Platform.programWithFlags
    { init = (\flags -> flags.start ! [])
    , update = (\msg model -> model ! [])
    , subscriptions = (always Sub.none)
    }

Compiled JavaScript

// Elm runtime but without Json_Decode
// ...

var _user$project$Bug$main = _elm_lang$core$Platform$programWithFlags(
  {
    init: function (flags) {
      return A2(
        _elm_lang$core$Platform_Cmd_ops['!'],
        flags.start,
        {ctor: '[]'});
    },
    update: F2(
      function (msg, model) {
        return A2(
          _elm_lang$core$Platform_Cmd_ops['!'],
          model,
          {ctor: '[]'});
      }),
    subscriptions: _elm_lang$core$Basics$always(_elm_lang$core$Platform_Sub$none)
  })(
  A2(
    _elm_lang$core$Json_Decode$andThen, // <---- This will crash at runtime
    function (start) {
      return _elm_lang$core$Json_Decode$succeed(
        {start: start});
    },
    A2(_elm_lang$core$Json_Decode$field, 'start', _elm_lang$core$Json_Decode$float)));
process-bot commented 7 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.

ckoster22 commented 7 years ago

Importing Json.Decode (even though I wasn't using it) fixed it for me

import Json.Decode exposing (..)
evancz commented 7 years ago

The new code gen will grab things by crawling from main so this stuff will get included. The mechanism is different at least.