lydell/elm-watch

Error related to debug mode?

Odalrick opened this issue · 9 comments

I'm getting this error when I try to use hot reloading:

Uncaught TypeError: can't access property "$", state is undefined
    $elm$browser$Debugger$Main$getLatestModel cart-widget.elm.js:19763
    wrapSubs cart-widget.elm.js:19778
    F2 cart-widget.elm.js:2872
    _Platform_initialize cart-widget.elm.js:4776
    _Platform_worker cart-widget.elm.js:4722
    F4 cart-widget.elm.js:2881
    init cart-widget.elm.js:5402
    initApp cart-widget.coffee:136
    <anonymous> cart-widget.coffee:465
    <anonymous> cart-widget.js.js:35501
    <anonymous> cart-widget.js.js:35503

I can't figure out what this error is telling me.

The compiled files are loaded one after another in the browser, so I don't think it is an execution order issue.

<script src="/js/cart-widget.elm.js"></script>
<script src="/js/cart-widget.js.js"></script>

I had it working before, but I tried enabling the debug mode; it failed and figured I'd work on that later once I got everything else working. I'm not sure if that is related to this issue.

I cant really see a way to "turn debug mode off" though. Will restarting elm-watch do it?

Some details that may be relevant:

cart-widget.coffee and cart-widget.js.js are the same file, webpack has compiled it and the original name is read from the source map in the backtrace. cart-widget.elm.js is the compiled Elm code.

I have a "backend" worker that maintains one state for the entire page and a few "frontend" apps that are just views. They send and receive messages through ports and the cart-widget.coffee is responsible for creating the different Elm apps and connecting them to each other.

Everything is served from docker and a Ruby on Rails app, but that should be irrelevant; the actual files are essentially served by a static file server, and the app doesn't get far enough to start failing http requests.

Hi!

I can't figure out what this error is telling me.

There was a crash in Elm’s compiled JS. That is not supposed to happen. Most likely it’s due to a bug in elm-watch triggered by some piece in your Elm code that I have never thought of before. It could also be due to a postprocess script. Do you use the “postprocess” feature of elm-watch?

I cant really see a way to "turn debug mode off" though.

It’s currently not possible to switch compilation mode when the app fails to initialize. (Maybe I can improve that, though.) A workaround is to delete elm-stuff/elm-watch/stuff.json, restart elm-watch and refresh the page.


Would you be able to share the broken cart-widget.elm.js with me somehow? Then I could debug it.

Would you be able to share the broken cart-widget.elm.js with me somehow?

Yes, on Monday, when I get back to the computer.

And no postprocess script. I was thinking of adding one to see if that helped work around this bug, but never got that far.

The only thing I can think of that's vaguely unique is having many instances of the same app running, but that's never been a problem before. Besides, that's not the app that's crashing; it's a Platform.worker. It doesn't have any UI.

I'm planning on moving it to a web worker, mostly to handle multiple tabs.

This is the elm-watch.json.

{
  "targets": {
    "CartWidget": {
      "inputs": ["elm/CartWidget.elm", "elm/CartViews.elm"],
      "output": "public/js/cart-widget.elm.js"
    },
    "AdminOrder": {
      "inputs": ["elm/AdminOrder.elm"],
      "output": "public/js/admin-order.js"
    },
    "BookingWidget": {
      "inputs": ["elm/BookingWidget.elm"],
      "output": "public/js/booking-widget.elm.js"
    }
  },
  "port": 44331
}

Never got around to trying the other targets.

Which of the .elm files contains the Platform.worker? CartWidget.elm?

Not that you are not even supposed to be able to switch to debug mode for workers:

image

Edit: I managed to reproduce it now. It happens when one input (CartWidget.elm) is a Platform.worker and another input (CartViews.elm) is Browser.element, of the same target. Then it’s possible to enable the debugger (since one of the inputs can use it), but it causes a crash. Good catch!

Interesting. The way I usually build, the way I want to replace, is an npm script:

"elm-live elm/CartWidget.elm elm/CartViews.elm --no-server -- --debug --output=public/js/cart-widget.elm.js",

I wonder why that's never been a problem before.

Because you weren’t using elm-watch :) elm-watch has its own hot reloading implementation, and I introduced a bug when programs that do and do not support the debugger are bundled in the same output.

I got back and deleted the elm-stuff directoty, and it started working again. :)

I have the crashing file saved, but I don't suppose there is much point in posting it.

The tool itself looks great. Do one thing, and do it well. I'll configure the rest to work with my set up. 👍

Great, I’ll try to fix the bug soon!

Fix released in v1.1.1.