Skip to content

Modules cannot have ports with same name #1450

Open
@b123400

Description

@b123400

Elm version: 0.17.0

I have two modules, they both have a port with the same name:

port module ModuleA exposing (main)

import Html exposing (text)
import Platform.Sub as Sub

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

main =
  text "Hello"
port module ModuleB exposing (main)

import Html exposing (text)
import Platform.Sub as Sub

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

main =
  text "Hey!"

And I compiled it by this command:

elm make ModuleA.elm ModuleB.elm --output combined.js

The generated JS file will output the following error:

Error: There can only be one port named `incomePort`, but your program has multiple.

These two modules are not connected and there should be no ambiguity between the ports. I think the ports name checking should be bounded to the module, instead of JS-file-wise.

By the way, when I generate the modules separately and include them in the same page, there is no error.

elm make ModuleA.elm --output a.js
elm make ModuleB.elm --output b.js
<script type="text/javascript" src="a.js"></script>
<script type="text/javascript" src="b.js"></script>

Is this behaviour intended?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions