elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Unhelpful error message when initializing app without passing in the node #2242

Open jessitron opened 2 years ago

jessitron commented 2 years ago

Quick Summary: ???

An example HTML file on this page: https://guide.elm-lang.org/webapps/ shows calling in to Elm like this:

<script>var app = Elm.Main.init();</script>

which produces a page that does not load, and fails with this error in the console:

VM37 main.js:3937 
         Uncaught TypeError: Cannot read properties of undefined (reading 'node')
    at VM37 main.js:3937:22
    at _Platform_initialize (VM37 main.js:1879:16)
    at VM37 main.js:3928:9
    at Object.init (VM37 main.js:20:33)
    at (index):10:30

image

The real failure is that my Elm code is returning a Browser.element instead of a Browser.document.

In this case, PLEASE TELL PEOPLE THAT.

SSCCE

the first example from the front page of https://guide.elm-lang.org/ 

Additional Details

While the "webapp" instruction page does talk about "First convert your main to return a document," It doesn't provide an example of how to do that. I struggled to find one. It is not a conversion that a beginner (or someone who hasn't touched Elm in years) can do.

I eventually found an example of an html file that works with a Browser.element on the "JavaScript Interop" page. When I wanted to build a trivial webapp, that's not where I went. I'll try to make a PR of some sort to the docs.

I really want the compiler to give a useful error message when 'node' is not provided to Elm.Main.init(). Something like "You need to tell Elm what element to load your app into. like..."

github-actions[bot] commented 2 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

jessitron commented 2 years ago

update: I can't find the docs repo, so I won't make a PR there. :-(

razzeee commented 2 years ago

Yeah, it's unfortunately not easy to discover https://github.com/evancz/guide.elm-lang.org