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

Cannot compile with ELM inside Docker on Mac M1 #2244

Open nicoebot opened 2 years ago

nicoebot commented 2 years ago

I'm trying to use ELM to compile a Vue App, which is inside a Docker Container, this works on Linux and Mac Intel.

Additional Details

Error

ERROR in ./src/elm/Main.elm
Module build failed: Error: Compiler process exited with error Compilation failed

    at ChildProcess.<anonymous> (/app/node_modules/node-elm-compiler/dist/index.js:131:35)
    at ChildProcess.emit (events.js:400:28)
    at ChildProcess.emit (domain.js:475:12)
    at maybeClose (internal/child_process.js:1058:16)
    at Socket.<anonymous> (internal/child_process.js:443:11)
    at Socket.emit (events.js:400:28)
    at Socket.emit (domain.js:475:12)
    at Pipe.<anonymous> (net.js:686:12)
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.

IzumiSy commented 2 years ago

I am also coming across this problem. It seems that OOM killer kills elm compiler process. Around 10GB are being consumed in my case, but sometimes not. It's realy unstable.

What is your Docker preference about CPU, memory, and swap?

ream88 commented 2 years ago

I have the same problem and was able to build Elm using the following article: https://dev.to/csaltos/elm-for-linux-arm64-32bc

os6sense commented 2 years ago

This is a hugely frustrating issue because the information available is very patchy, not particularly helped by the 0.19.1-4 or 0.19.1-5 approaches (i.e. 0.19.1-4 doesn't actually work), and is compounded with issues where the docker daemon itself is crashing due to memory issues in the scenario @IzumiSy mentions.

I've successfully built binaries using the approach @ream88 mentions, however the binary isn't statically compiled and hence won't run, for example, on alpine. I've yet to manage to get a build working on alpine, I know zero about the Haskell tooling. if anyone can share insights on how to produce a portable binary here, it would be hugely appreciated

I should also mention I've been able to install via nix-env, but then nix isn't particularly easy to install either.

sashaafm commented 2 years ago

I'm running Elm inside Docker in a Mac M1 and it seems to work by installing it like this:

    RUN curl -L -o elm.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz \
    && gunzip elm.gz \
    && chmod +x elm \
    && mv elm /usr/local/bin/

The only problem so far is that compilation takes a few seconds to start (was instantaneous in the Intel Mac)

bwells commented 2 years ago

@sashaafm Elm still dies OoM for me with this suggestion. What base image are you using? I've tried ubuntu and alpine.

sashaafm commented 2 years ago

@bwells I'm using the elixir:1.11 base image

sashaafm commented 1 year ago

@bwells back when I posted this I was only using an M1 Mac with 16GB RAM. I now started using an M1 Mac with 8GB and did a full migration from the other Mac. In this 8GB Mac I lowered the memory limit in Docker to 4GB since I didn't want to use as many resources as the other one. However, Elm compilation started failing with OOM like you described.

I found out that setting the limit to 8GB back again now works for the 8GB Mac as well. So I guess that Elm compilation in the M1 Macs require at least 8GB of memory in order to not be killed? I don't see the memory pressure going to those limits though

bwells commented 1 year ago

Thanks so much for reaching out. I was able to determine that raising the Docker VM memory limit to 7GB with my codebase would allow successful compiles. I'm on a 24 GB M2 Air these days, so that amount of memory is workable, but still feels a bit silly.

I also don't actually see the memory pressure triggering the OOM kill and this still feels like room for improvement out of Elm and/or Haskell, but I'm glad to have a working solution again.