Skip to content

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

@mayoff

Description

@mayoff

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions