Uncaught TypeError: Cannot read property 'tag' of undefined

809 views
Skip to first unread message

Aditya Vishwakarma

unread,
Jul 28, 2016, 4:57:41 PM7/28/16
to Elm Discuss
Hi

I am getting Uncaught TypeError: Cannot read property 'tag' of undefined in a sample code I built to tryout elm. The error happen when I send JSON data across the elm port from JS side. 


To run. Simply do
npm install && elm package install
npm start

and open http://localhost:8080/. A listing of /r/elm should show up when the app works. 

A screenshot of the exact location where the error occurs:


People on slack recommended me to remove elm-stuff/build-artifacts and try again. It didn't work so I removed node_modules and elm-stuff directories and reinstalled the whole thing. Didn't work as well. 
The code was working before I decided to clean it up a little to show to my teammates. Stopped working the moment I shared the github link with them. :|

anyone got any ideas on this?

Aditya Vishwakarma

unread,
Jul 31, 2016, 5:01:01 AM7/31/16
to Elm Discuss
Hi

So I dug deeper into this issue. turns out that the JS code for my port module was being emitted before the JS of Json.Decode module. 

After some research, I found that if the project's port module has:
  • Name beginning with a letter before J, and
  • does not have a declared dependency on Json.Decode
Then the elm compiler will emit the port module code before `Json.Decode` which causes all decoders to be `Undefined`. This results in all user defined incoming ports to stop throw exceptions.

Duane Johnson

unread,
Aug 1, 2016, 12:01:09 AM8/1/16
to elm-d...@googlegroups.com
Cool bug find :) Is it tracked on https://github.com/elm-lang/elm-compiler/issues ?

--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Walter

unread,
Aug 8, 2016, 1:00:16 PM8/8/16
to Elm Discuss
It doesn't seem like it is tracked. I ran into the same(?) issue in my project and I tried to create a SSCCE so I could file an issue, but the thing is I cannot get a SSCCE to fail like my project. My projec tis in the middle of a bigger refactoring, which makes it particularly hard for me to boil it down to a SSCCE.

@Aditya: can you share some more information? In my case, my port module is called "Ports". If I do not have an import statement for Json.Decode, I run into the very error you mentioned at the beginning. Adding the import statement fixes the issue.

Janis Voigtländer

unread,
Aug 8, 2016, 2:14:30 PM8/8/16
to elm-d...@googlegroups.com

@Robert, maybe yours is a new bug, that was introduced with core version 4.0.3 or 4.0.4 (released just a few days ago)? See https://github.com/elm-lang/core/issues/683.


To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.

Aditya Vishwakarma

unread,
Aug 8, 2016, 2:42:39 PM8/8/16
to Elm Discuss
@robert: are you using webpack loader? We tracked this bug to an elm-webpack-loader behaviour. here is the issue. https://github.com/rtfeldman/elm-webpack-loader/issues/60

For now, the workaround I am using is to import Json.Decode in my Ports file.

Robert Walter

unread,
Aug 9, 2016, 8:01:47 AM8/9/16
to Elm Discuss
Hi Janis,
yes, this seems to be related. I created an SSCCE to the best of my abilities: https://github.com/RobertWalter83/sscce-elm-ports-uncaughtError
Check out the readme if you are interested.

Will post a comment to the isse you pointed me to.

Robert Walter

unread,
Aug 9, 2016, 8:02:45 AM8/9/16
to Elm Discuss
Hi Aditya, 
thanks for pointing that out. I do not use the webpack-loader. I think it is related to what Janis mentioned.
Robert
Reply all
Reply to author
Forward
0 new messages