dillonkearns / elm-pages

Hybrid Elm framework with full-stack and static routes.
https://elm-pages.com
BSD 3-Clause "New" or "Revised" License
658 stars 97 forks source link

Compatibility Keys match, but elm-pages says they don't when running script #457

Closed Erudition closed 8 months ago

Erudition commented 8 months ago

I can build and dev and run elm-pages just fine, until I try to run an add pages script, when for some reason I get this:

> elm-pages-app@ add-static-page /home/adroit/Projects/elm-website
> elm-pages run AddStaticRoute "Project_"

-- Incompatible NPM and Elm package versions --------------- 
The NPM package and Elm package you have installed are incompatible. If you are updating versions, be sure to update both the elm-pages Elm and NPM package.

The elm-pages NPM package is ahead of the elm-pages Elm package. Try updating the elm-pages Elm package?
 ELIFECYCLE  Command failed with exit code 1.

package.json contains:

  "devDependencies": {
    "elm-codegen": "^0.3.0",
    "elm-optimize-level-2": "^0.3.5",
    "elm-pages": "3.0.12",
    "elm-review": "^2.10.2",
    "elm-tooling": "^1.14.0",
    "vite": "^4.3.5"
  },

elm.json contains:

    "dependencies": {
        "direct": {
...
            "dillonkearns/elm-pages": "10.0.3",

The docs indicate that these two versions are a match.

The contents of ~/.elm/0.19.1/packages/dillonkearns/elm-pages/10.0.3/src/Pages/Internal/Platform/CompatibilityKey.elm are:

module Pages.Internal.Platform.CompatibilityKey exposing (currentCompatibilityKey)

currentCompatibilityKey : Int
currentCompatibilityKey =
    21

The contents of ~/Projects/elm-website/node_modules/elm-pages/generator/src/compatibility-key.js are:

export const compatibilityKey = 21;

export const packageVersion = "3.0.11";

So the compatibility Key is the same. Note that this is from version 3.0.12, not 3.0.11. So that packageVersion string is wrong. However, changing it to 12 does not fix anything.

In addition to getting help with this issue, I'd like to suggest the version mismatch error message be more helpful -- e.g. what are the two versions, what are the compatibility keys.

dillonkearns commented 8 months ago

Check your script/elm.json. Your script/ is a separate project, just like an elm-review project is. The reason for that is that you could have some dependencies that you want to install for your scripts, but not for your web application, or vice versa.

Erudition commented 8 months ago

So whenever I upgrade elm-pages, I have to make sure to update elm-pages inside the script folder as well? I did not know this.

Erudition commented 8 months ago

Okay, sure enough cd scripts && elm-json upgrade --unsafe did the trick, phew! In case anyone else runs into this issue. Thank you!

dillonkearns commented 8 months ago

Yeah, so actually an elm-pages scripts project is a completely independent Elm project. You can even have a standalone script project with no elm-pages web application at all.

It would probably be nice to have the error message point to the file path of the elm.json which has the outdated package to make it very explicit.

Erudition commented 8 months ago

Agreed. Or better yet, modify the elm.json to match the elm-pages project's versions.

dillonkearns commented 8 months ago

You can't assume that you can update their elm.json, for one thing you don't know if that's their intention, but also there could be conflicting dependencies making it impossible to manually update the elm.json. But yeah, a nice error message to indicate explicitly where the problem is coming from would be nice, but the user needs to choose if and when they want to upgrade.

dillonkearns commented 8 months ago

You could imagine for example that there's a breaking API change, so the user might want to defer updating their dependencies in their script project. It's just not an option to assume the user wants to upgrade.