jmfirth/generator-elm-spa

"Cannot read property 'forEach' of undefined" on dev server in Chrome

Opened this issue · 9 comments

I thought I would open an issue for the problem encountered by a few users in this reddit thread.

It is my understanding from that same thread that this might be a problem with elm 0.16.0 itself. As such, please feel free to close this issue if you feel no change to the generator should be made.

In the meantime, if anyone has a workaround, please share :)

Issue:

When running the server task, the "dist" mode works fine, but the "dev" mode throws a js error:

On Chrome: "Cannot read property 'forEach' of undefined"
On Safari: "undefined is not an object (evaluating 'node.kids.forEach')"

Chrome 48.0.2564.109 (64-bit)
OSX 10.11.3
Safari 9.0.3 (11601.4.4)
node v5.5.0
npm v3.7.2

I'll leave it open to track it for others that run into the problem. Thanks for opening an issue for this!

My current understanding of this issue is that it affects Mac OS/elm 0.16.0 users running the app in debug mode with the elm-reactor, either by using the development build or running the app entry point directly. The app is still functional when run in distribution mode or running directly without debug mode. This issue appears to have to do with ports as is introduced by the functionality of the router.

I'm going to remove the wontfix label and dabble with any alternatives that would work.

I'm torn: not only is this is likely the best router out there today, and it works great, but I'd be removing it just to introduce the time traveling debugger- a tool that, in it's current form, is of little benefit to most applications in this space. However, that it doesn't work today is likely enough to detract a significant number of people who might otherwise find this generator useful.

I didn't realize the issue was only present on Mac OS. I will try to setup a minimal Linux vm when I get home and use that while waiting for an eventual elm release that fixes this.

I'm new to all this but from what I've seen in the sample app, the router is very interesting and simple to understand, I'm all for keeping it.

For reference:

I whipped up a quick install of Debian 8 in Parallels and I'm getting the same problem.

I installed node 5.6.0 via the official instructions.

OS: Linux debian-vm 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 GNU/Linux
Node: v5.6.0
NPM: v3.6.0

As previously stated, the dist build is working fine, so all that is left is to wait for the upcoming elm release that fixes this.

I have also encountered this error, and I tried running it on my Windows 10. Any advances in the topic?

Not yet, no. Last I looked, roughly a month ago, there were a few competing alternatives that were promising but involved trade-offs to introduce that would derail the spirit of what this generator is trying to accomplish. I will take a look at the landscape again this week to see if any of these trade-offs have been alleviated.

Just do the install, generated a new project and npm run server, Windows 10, Chrome, same thing: Cannot read property 'forEach' of undefined for dev. Dist is fine.

Related to this: elm-lang/elm-reactor#145
Will be fine if this PR goes in: elm-lang/elm-reactor#149

Go to the location you installed elm and open debug.js, for example Elm\0.16\share\reactor\_reactor\debug.js

Line 13399 has the addAllToDict function, just replace with

function addAllToDict(node)
{
    nodesById[node.id] = node;
        if (!node.isOutput) {
            node.kids.forEach(addAllToDict);
        }
}

Dev now works :)

@CumpsD Thanks for the description of a temporary workaround!