compiler
compiler copied to clipboard
Unhelpful error message when initializing app without passing in the node
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
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/
- Elm: 0.19.1
- Browser: Edge
- Operating System: Windows
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..."
Thanks for reporting this! To set expectations:
- Issues are reviewed in batches, so it can take some time to get a response.
- Ask questions in a community forum. You will get an answer quicker that way!
- If you experience something similar, open a new issue. We like duplicates.
Finally, please be patient with the core team. They are trying their best with limited resources.
update: I can't find the docs repo, so I won't make a PR there. :-(
Yeah, it's unfortunately not easy to discover https://github.com/evancz/guide.elm-lang.org