GHCJS (experimental)

To use GHCJS with stack, place a GHCJS version in the compiler field of stack.yaml. After this, some stack commands should work with GHCJS. In particular:

  • stack setup will install GHCJS from source and boot it, which takes a long time.

  • stack build will compile your code to JavaScript. In particular, the generated code for an executable ends up in $(stack path --local-install-root)/bin/EXECUTABLE.jsexe/all.js (bash syntax, where EXECUTABLE is the name of your executable).

You can also build existing stack projects which target GHC, and instead build them with GHCJS. For example: stack build --compiler ghcjs-

There are advanced options for stack setup: --ghcjs-boot-options (one word at a time) and --[no-]ghcjs-boot-clean which will pass your settings down to the ghcjs-boot. You will need to know exactly what you are doing with them.

Sidenote: If you receive a message like The program 'ghcjs' version >=0.1 is required but the version of .../ghcjs could not be determined., then you may need to install a different version of node. See issue #1496.

Example Configurations

GHCJS repacked for snapsnots lts-8 and lts-9

Please see the ghcjs-stack-dist repository for lts-8 and lts-9 configurations and refer to the README for common issues.

Support for > lts-9 snapshots (GHC 8.2 and above) is currently work in progress.

GHCJS repacked for snapsnots < lts-8

These versions of GHCJS were created by Marcin Tolysz, and were particularly crafted to include package versions which match those expected by particular stackage snapshots.

For ghcjs based on ghc-7.10.3 one could try:

resolver: lts-6.30
compiler: ghcjs-
compiler-check: match-exact

         sha1: 2371e2ffe9e8781808b7a04313e6a0065b64ee51

Or for the latest one based on ghc-8.0.1 (with more features):

resolver: lts-7.19
compiler: ghcjs-
compiler-check: match-exact

           sha1: d2cfc25f9cda32a25a87d9af68891b2186ee52f9

The latter can be generated via: the former is a bit more manual. Those bundles are only tested against the latest node-7.4.0.

In order to correctly boot and use ghcjs, one might need to install alex happy hscolour hsc2hs with the normal ghc.

Older resolvers:

resolver ghcjs url sha1
lts-7.19 0.2.1 d2cfc25f9cda32a25a87d9af68891b2186ee52f9
lts-7.15 0.2.1 30d34e9d704bdb799066387dfa1ba98b8884d932
lts-7.14 0.2.1 530c4ee5e19e2874e128431c7ad421e336df0303
lts-7.13 0.2.1 0d2ebe0931b29adca7cb9d9b9f77d60095bfb864
lts-7.8 190300a3725cde44b2a08be9ef829f2077bf8825
lts-7.7 ce169f85f1c49ad613ae77fc494d5565452ff59a
lts-7.5 450e81028d7f1eb82a16bc4b0809f30730c3e173
lts-7.4 ed77b3c15fedbadad5ab0e0afe1bd42c0a8695b4
lts-7.3 3196fd5eaed670416083cf3678396d02c50096de
lts-7.2 a41ae415328e2b257d40724d13d1386390c26322
lts-7.1 e640724883238593e2d2f7f03991cb413ec0347b
lts-6.25 0.2.0 3c87228579b55c05e227a7876682c2a7d4c9c007
lts-6.21 80b83f85dcec182093418e843979f4cee092fa85
lts-6.20 a6cea90cd8121eee3afb201183c6e9bd6bacd94a
lts-6.19 ef4264d5a93b269ee4ec8f9d5139da030331d65a
lts-6.18 3e9f345116c851349a5a551ffd94f7e0b74bfabb

If you do not use the same resolver, say, an older LTS snapshot, you will get some warnings like this:

Ignoring that the GHCJS boot package "aeson" has a different version,, than the resolver's wanted version,
Ignoring that the GHCJS boot package "attoparsec" has a different version,, than the resolver's wanted version,
Ignoring that the GHCJS boot package "scientific" has a different version,, than the resolver's wanted version,

These warnings can usually be safely ignored, but they do indicate a divergence between your snapshot's packages, and those that are being used to compile your project. You will normally get these warnings when using a GHCJS tarball that has not been packaged with a particular snapshot in mind.

GHCJS (old base)

If you want to build some older GHCJS packages, you may need to use the "old base" GHCJS. To do this, use the following compiler info:

compiler: ghcjs-
compiler-check: match-exact

Custom installed GHCJS

In order to use a GHCJS installed on your PATH, just add the following to your stack.yaml:

compiler: ghcjs-0.2.0_ghc-7.10.2

(Or, ghcjs-0.1.0_ghc-7.10.2 if you are working with an older version)

This is particularly useful when you have built GHCJS from source.

Project with both client and server

For projects with both a server and client, the recommended project organization is to put one or both of your stack.yaml files in sub-directories. This way, you can use the current working directory to specify whether you're working on the client or server. This will also allow more straightforward editor tooling, once projects like ghc-mod and haskell-ide-engine support GHCJS.

For example, here's what a script for building both client and server looks like:


# Build the client
stack build --stack-yaml=client/stack.yaml

# Copy over the javascript
rm -f server/static/all.js
cp $(stack path --stack-yaml=client/stack.yaml --local-install-root)/bin/client.jsexe/all.js server/static/all.js

# Build the server
stack build --stack-yaml=server/stack.yaml

You can also put both the yaml files in the same directory, and have e.g. ghcjs-stack.yaml, but this won't work well with editor integrations.

Using stack without a snapshot

If you don't want to use a snapshot, instead place the ghcjs version in the resolver field of your stack.yaml. This is also necessary when using stack < 0.1.8.

Setting up GHCJS on Windows

If stack setup command fails to successfully complete with message: commitBuffer: invalid argument (invalid character), it means you have a locale problem. This problem is not exclusive to GHCJS, and might happen also during other builds. A workaround is to set Language for non-Unicode programs to English (US). For details see stack issue #1448.