Core: Uncaught TypeError if Json.Decode is not imported (module loading order problem?)

Created on 9 Aug 2016  路  4Comments  路  Source: elm/core

I experience an issue which might be related to #683.

I created a SSCCE to illustrate the problem.

Im working on Windows 10. I use Elm 0.17.1, core 4.0.3.

Description:
I have a port module where I have defined all my app's ports. If this module does not import "Json.Decode", I get an Uncaught TypeError exception:
ex

I am aware of this discussion. I do not use elm-webpack-loader.

Most helpful comment

It appears that the presence of a port module alone doesn't inform the compiler of the need to import Json.Decode. Here's a succinct SSCCE for which you can examine the generated code and note the absence of Json.Decode

port module Main exposing (..)

port example : (String -> msg) -> Sub msg

value =
    1

All 4 comments

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

It appears that the presence of a port module alone doesn't inform the compiler of the need to import Json.Decode. Here's a succinct SSCCE for which you can examine the generated code and note the absence of Json.Decode

port module Main exposing (..)

port example : (String -> msg) -> Sub msg

value =
    1

@lukewestby, feel free to close issues and open nicer ones if you figure things out like this! I did this with #703.

Also running into this issue with React Native talking to Elm program via ports. The error is

Can't find variable _elm_lang$core$Json_Decode$string

Adding import Json.Decode solves the problem. See relevant code here.

Was this page helpful?
0 / 5 - 0 ratings