Getting Elm to Run on Heroku


This book is about a man who made a bunch of random things in ye old ways out of Ash. Now Ash is not Elm, but they are both trees, and this book is excellent and it is not about computers.

I am writing some front ends this week in elm, the language, and I figured what better place to deploy my fancy new elm front end than heroku (or possibly zeit now). In order to do this I decided to build a Dockerfile that the calls a Makefile (thanks Joe from the previous post).  This actually took a while for me to do.

This is the Dockerfile

FROM node:latest

COPY package.json .
RUN npm install elm@elm0.19.0
RUN npm install http-server

COPY elm.json .
COPY . .


RUN chmod 777 Makefile
RUN make

CMD http-server -p $PORT dist

And this is the Makefile

export PATH := ../../node_modules/.bin:$(PATH)
export SHELL := /usr/bin/env bash

all: build elm index
mkdir -p dist \
mkdir -p build
elm make src/Main.elm –output build/main.js
cat build/main.js build/bootstrap.js > dist/bundle.js
cat build/index.html > dist/index.html

This all works now, but I will recall my tale of woe.

First off, I was installing the npm packages globally and without a version. This lead me down the dark path of loading ubuntu and downloading sudo – none of which worked.  Then a bunch of people on Zulip, at RC, suggested I NOT install globally. This sort of worked, but then I got an error regarding my package.json. Where was it ??? No where, because I writing elm. But I did npm init -because YOLO.  The Docker seemed to work but the Makefile was busted. It could not find elm. I was filled with shame.

Luckily I ran into Tenor and forced him to look at my Makefile and within 2 seconds he said AHAH you need:

export PATH := ../../node_modules/.bin:$(PATH)
export SHELL := /usr/bin/env bash

And low and behold it worked. We both talked about how great Make is and I am feeling pretty good. Next up I am going to look at Elm and Rust – because maybe I want to rewrite my backends and I saw this link when I was trying to deal with my elm Docker issues.

Leave a Reply