elm-spa icon indicating copy to clipboard operation
elm-spa copied to clipboard

Debug remnants build failure causes empty error message during production builds

Open autophagy opened this issue 3 years ago • 4 comments

Hi! Just wanted to first say thank you for creating elm-spa - I've had a super great experience building stuff with it :sparkles:

I've found that using functions from the Debug core library causes elm-spa build to fail, as expected, but without any kind of build message. For example, in basic elm:

module Main exposing (..)

import Html exposing (text)

main =
  text <| Debug.toString "Hello!"
λ elm make src/Main.elm
Success!     

    Main ───> index.html

λ elm make src/Main.elm --optimize 
Success!     
-- DEBUG REMNANTS --------------------------------------------------------------

There are uses of the `Debug` module in the following modules:

    Main

But the --optimize flag only works if all `Debug` functions are removed!

Note: The issue is that --optimize strips out info needed by `Debug` functions.
Here are two examples:

    (1) It shortens record field names. This makes the generated JavaScript is
    smaller, but `Debug.toString` cannot know the real field names anymore.

    (2) Values like `type Height = Height Float` are unboxed. This reduces
    allocation, but it also means that `Debug.toString` cannot tell if it is
    looking at a `Height` or `Float` value.

There are a few other cases like that, and it will be much worse once we start
inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,
resulting in unpredictable behavior. I hope that clarifies why this restriction
exists!

But trying the same thing with elm-spa (I'm using 6.0.4):

module Pages.Home_ exposing (view)

import Html
import View exposing (View)

view : View msg
view =
    { title = "Homepage"
    , body = [ Html.text <| Debug.toString "Hello, world!" ]
    }

Results in:

λ elm-spa build 

! elm-spa failed to understand an error

Please report the output below to https://github.com/ryannhg/elm-spa/issues

-----

{}

-----

! elm-spa failed to understand an error

Please send the output above to https://github.com/ryannhg/elm-spa/issues

I suspect this might actually be a problem with node-elm-compiler since it looks like its returning an empty error from compileToString?

autophagy avatar Jun 13 '21 10:06 autophagy

having the error messages from the elm compiler directly would be super good!

Narice avatar Jul 13 '21 17:07 Narice

It is possible to use elm-live or do you recommend vite as a replacement to get error messages in this case @ryannhg?

Narice avatar Jul 13 '21 17:07 Narice

It is possible to use elm-live or do you recommend vite as a replacement to get error messages in this case @ryannhg?

hey @Narice – elm-live is a great dev server, so i recommend using whatever you prefer.

the setup for vite, elm-live, webpack, or any other server is pretty similar so pick the one that works best for you!

i only included a vite example to demonstrate how to use elm-spa watch and elm-spa gen alongside a 3rd party tool.

ryan-haskell avatar Jul 13 '21 17:07 ryan-haskell

@ryannhg thank you very much! I'll do that for now then! When elm-spa server will show errors I'll probably switch back to it.

Narice avatar Jul 15 '21 10:07 Narice