elm / compiler

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

elm install can produce incompatible dependencies for elm-test #1860

Open andys8 opened 5 years ago

andys8 commented 5 years ago

Issue

It's possible to run elm install <package> and the resulting elm.json can't be used. The compiler will fail with "The dependencies in your elm.json are not compatible."

Reproduce issue

Valid elm.json

{
    "type": "application",
    "source-directories": [
        "src"
    ],
    "elm-version": "0.19.0",
    "dependencies": {
        "direct": {
            "NoRedInk/elm-json-decode-pipeline": "1.0.0",
            "Punie/elm-reader": "1.0.0",
            "arturopala/elm-monocle": "2.1.0",
            "ccapndave/elm-update-extra": "4.0.0",
            "cuducos/elm-format-number": "6.0.2",
            "danyx23/elm-uuid": "2.1.2",
            "elm/browser": "1.0.1",
            "elm/core": "1.0.2",
            "elm/http": "1.0.0",
            "elm/json": "1.1.2",
            "elm/time": "1.0.0",
            "elm/url": "1.0.0",
            "elm-community/dict-extra": "2.4.0",
            "elm-community/list-extra": "8.1.0",
            "justinmimbs/time-extra": "1.1.0",
            "mgold/elm-nonempty-list": "4.0.0",
            "rtfeldman/elm-css": "16.0.0",
            "rtfeldman/elm-iso8601-date-strings": "1.1.2",
            "rtfeldman/elm-validate": "4.0.1",
            "ryannhg/date-format": "2.3.0"
        },
        "indirect": {
            "Skinney/murmur3": "2.0.8",
            "elm/parser": "1.1.0",
            "elm/random": "1.0.0",
            "elm/regex": "1.0.0",
            "elm/virtual-dom": "1.0.2",
            "justinmimbs/date": "3.1.2",
            "myrho/elm-round": "1.0.4",
            "rtfeldman/elm-hex": "1.0.0"
        }
    },
    "test-dependencies": {
        "direct": {
            "drathier/elm-test-tables": "3.0.0",
            "elm/html": "1.0.0",
            "elm-explorations/test": "1.2.0"
        },
        "indirect": {
            "elm/bytes": "1.0.5",
            "elm/file": "1.0.1",
            "elm-community/random-extra": "3.0.0"
        }
    }
}

Steps

Resulting invalid elm.json

{
    "type": "application",
    "source-directories": [
        "src"
    ],
    "elm-version": "0.19.0",
    "dependencies": {
        "direct": {
            "NoRedInk/elm-json-decode-pipeline": "1.0.0",
            "Punie/elm-reader": "1.0.0",
            "arturopala/elm-monocle": "2.1.0",
            "ccapndave/elm-update-extra": "4.0.0",
            "cuducos/elm-format-number": "6.0.2",
            "danyx23/elm-uuid": "2.1.2",
            "elm/browser": "1.0.1",
            "elm/core": "1.0.2",
            "elm/http": "1.0.0",
            "elm/json": "1.1.2",
            "elm/time": "1.0.0",
            "elm/url": "1.0.0",
            "elm-community/dict-extra": "2.4.0",
            "elm-community/list-extra": "8.1.0",
            "justinmimbs/time-extra": "1.1.0",
            "mgold/elm-nonempty-list": "4.0.0",
            "rtfeldman/elm-css": "16.0.0",
            "rtfeldman/elm-iso8601-date-strings": "1.1.2",
            "rtfeldman/elm-validate": "4.0.1",
            "ryannhg/date-format": "2.3.0"
        },
        "indirect": {
            "Skinney/murmur3": "2.0.8",
            "elm/html": "1.0.0",
            "elm/parser": "1.1.0",
            "elm/random": "1.0.0",
            "elm/regex": "1.0.0",
            "elm/virtual-dom": "1.0.2",
            "justinmimbs/date": "3.1.2",
            "myrho/elm-round": "1.0.4",
            "rtfeldman/elm-hex": "1.0.0"
        }
    },
    "test-dependencies": {
        "direct": {
            "drathier/elm-test-tables": "3.0.0",
            "elm/html": "1.0.0",
            "elm-explorations/test": "1.2.0"
        },
        "indirect": {
            "elm/bytes": "1.0.5",
            "elm/file": "1.0.1",
            "elm-community/random-extra": "3.0.0"
        }
    }
}

What happenend?

"elm/html": "1.0.0" was added to dependencies.indirect. But it's also existing in test-dependencies.direct. Removing it from dependencies.indirect by hand will resolve the issue.

It is intentional to not have the dependency elm/html in the src. It should not be used by accident. It is necessary for testing though.

andys8 commented 4 years ago

Ran into this issue again, today. It is still the case with 0.19.1. It is not the case if zwilias/elm-json is used to install packages instead of the elm compiler.

andys8 commented 4 years ago

Demo

https://github.com/andys8/elm-compiler-incompatible-test-dependency-demo

elm-json

elm-test will work

https://github.com/andys8/elm-compiler-incompatible-test-dependency-demo/commit/0bab8fff2853a76791a0a59753241f47bad1263f

elm 0.19.0

https://github.com/andys8/elm-compiler-incompatible-test-dependency-demo/commit/6304aeff2e24fa495e8749f30617a974c0b021e6

npx elm-test@latest-0.19.0 --compiler /home/ascharf/bin/elm-0.19.0
-- INVALID PACKAGE DEPENDENCIES --------------------------------------- elm.json

The dependencies in your elm.json are not compatible.

Did you change them by hand? Try to change it back! It is much better to add
dependencies with elm install or the dependency management tool in elm reactor.

Please ask for help on the Elm slack <http://elmlang.herokuapp.com/> if you try
those paths and still cannot figure it out!

Compilation failed while attempting to build /tmp/elmjson/tests/MyTest.elm

elm 0.19.1

https://github.com/andys8/elm-compiler-incompatible-test-dependency-demo/commit/232bb10d87a8030c5361664f7f842ec1e007ff44

$ elm-test

-- ERROR IN DEPENDENCIES ---------------------------------------------- elm.json

It looks like the dependencies elm.json in were edited by hand (or by a 3rd
party tool) leaving them in an invalid state.

Try to change them back to what they were before! It is much more reliable to
add dependencies with elm install or the dependency management tool in
elm reactor.

Please ask for help on the community forums if you try those paths and are still
having problems!

Compilation failed while attempting to build /tmp/elmjson/tests/MyTest.elm

Difference

The issue is elm adding this indirect dependency. elm-json doesn't do that.

image

Note: elm.json pretty printed for better diffs

zwilias commented 4 years ago

Technically elm is correct and elm-json is wrong here. elm/html is a dependency of elm/browser, so it should be in your indirect dependencies: it is necessary to build your application in non-test mode. elm-json wrongly filters it out. I should look into that, I suppose.

I think when all is said and done, the issue here is that elm-test fails to run, given a valid elm.json file...

andys8 commented 4 years ago

Interesting! Thanks for the input.

So, based on this explanation, a guess would be the actual issue being elm-test merging direct test dependency elm/html with indirect build dependency elm/html leading to elm compiler failing to compile?

zwilias commented 4 years ago

Yeah, elm-test sort of blindly merges together dependencies, with the end result (in this instance) having both a direct and an indirect dependency on elm/html. The compiler notices that this is rather fishy and rejects the generated elm.json. I'm pretty sure one of the issues linked from https://github.com/rtfeldman/node-test-runner/pull/356 will be about the same thing!