Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guide Ports page should explain error "Cannot read property 'xxx' of undefined" #831

Open
mayoff opened this issue Dec 20, 2019 · 3 comments

Comments

@mayoff
Copy link

mayoff commented Dec 20, 2019

Yesterday I installed Elm 0.19.1 yesterday and started playing with it. I have read the entire guide.

Today I wanted to try using a port. I changed my module declaration and defined the port. Then I edited my index.html to send a value to the port. I got a Javascript error:

Uncaught TypeError: Cannot read property 'myPort' of undefined

After too much time poking around in the Javascript debugger and a little Googling, I discovered that Elm (as of 0.19 apparently) discards ports that aren't used on the Elm side. I don't recall reading about this in the guide. I cannot find any mention of it on the Ports page of the guide. Anyway, adding a subscription to the port fixed the problem.

I also joined the Elm slack today and this evening at 8:04 PM US/Central time, in the #beginners channel, someone else asked about the same problem.

It would be nice for the guide to explain that a port must be used on the Elm side or else it won't be available on the Javascript side and will trigger this specific error.

@jussihuotari
Copy link

Did you discover the exact piece of code where Elm would discard the unused ports?

FWIW, I've gotten the same error too, and it's just been invalid browser cache. The browser hadn't loaded the updated elm.js containing the port definition. In this case a simple shift-cmd-r i.e. hard reload helped me.

@rlefevre
Copy link
Member

rlefevre commented Feb 11, 2020

@jussihuotari
I think that unused ports are removed by Dead Code Elimination, like any other unused code.

@trebsirk
Copy link

trebsirk commented Apr 7, 2020

just encountered this problem. pressing cmd-shift-r on the page in the browser worked for me.
https://en.wikipedia.org/wiki/Wikipedia:Bypass_your_cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants