elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Confusing "Module name mismatch" error when the import uses the wrong casing #2231

Open jfmengels opened 2 years ago

jfmengels commented 2 years ago

Quick Summary: When a module imports another module with the wrong casing (import ABC when the module is named Abc), the compiler reports a MODULE NAME MISMATCH which doesn't indicate the real source of the problem.

SSCCE

In case it's helpful, I've made this SSCCE into its own repo: https://github.com/jfmengels/elm-compiler-case-mismatch-sscce

-- src/Main.elm
module Main exposing (main)

import Html exposing (text)
-- Notice the casing for this module is wrong
import Mymodule

main = text "Hello world"
-- src/MyModule.elm
module MyModule exposing (a)

a = 1

Additional Details

When you run the Elm compiler with the example above, you get this error message:

-- MODULE NAME MISMATCH --------------------------------------- src/Mymodule.elm

It looks like this module name is out of sync:

1| module MyModule exposing (a)
          ^^^^^^^^
I need it to match the file path, so I was expecting to see `Mymodule` here.
Make the following change, and you should be all set!

    MyModule -> Mymodule

Note: I require that module names correspond to file paths. This makes it much
easier to explore unfamiliar codebases! So if you want to keep the current
module name, try renaming the file instead.

This error message is actively unhelpful, because it makes you look at the wrong thing. Instead, it should tell you either that this import does not exist, or tell you that the casing is wrong on the import.

I don't know if this replicates on case-sensitive machines like Linux, it might be due to Mac's case-insensitivity on file paths.

github-actions[bot] commented 2 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.