Skip to content

[question] Can't build with cabal using the JS backend

I'm trying to build a project using the JS backend in GHC 9.6 (or 9.7.20230406). I'm getting GHC from nixpkgs (pkgsCross.ghcjs.haskell.compiler.ghc96) and running this command:

cabal --with-compiler=javascript-unknown-ghcjs-ghc --with-ghc-pkg=javascript-unknown-ghcjs-ghc-pkg build

This eventually fails to build lens, because ghcjs_HOST_OS is not set, and this file relies on it. Setting --ghc-option='-Dghcjs_HOST_OS' doesn't change anything.

So I tried this instead:

cabal --ghcjs --with-ghcjs=javascript-unknown-ghcjs-ghc --with-ghcjs-pkg=javascript-unknown-ghcjs-ghc-pkg build

Which now complains that it can't determine the version of javascript-unknown-ghcjs-ghc. And indeed, Cabal is trying to run javascript-unknown-ghcjs-ghc --numeric-ghcjs-version, which is not a recognised flag.

How do I use the new JS backend with Cabal?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information