# GHC JS Backend - Improve compiled size

**URL:** <https://discourse.haskell.org/t/ghc-js-backend-improve-compiled-size/12098>\
**Category:** Uncategorized\
**Created:** [May 14, 2025, 9:06pm UTC](https://discourse.haskell.org/t/ghc-js-backend-improve-compiled-size/12098 "2025-05-14T21:06:07Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![panmona](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/panmona/32/4993_2.png) [@panmona](https://discourse.haskell.org/u/panmona)\
**Post date:** [May 17, 2025, 2:11pm UTC](https://discourse.haskell.org/t/ghc-js-backend-improve-compiled-size/12098/17 "2025-05-17T14:11:28Z")

</div>

True. Sorry about that. These are the errors:

```haskell
$ npx google-closure-compiler --js=all.js --externs all.externs.js --js_output_file=out.min.js --compilation_level ADVANCED_OPTIMIZATIONS --language_in UNSTABLE 

... warnings ...

all.js:8831:11: ERROR - [JSC_UNDEFINED_VARIABLE] variable MK_INTEGER_S is undeclared
  8831| return MK_INTEGER_S(parseInt(str, 10));
                   ^^^^^^^^^^^^

all.js:8833:11: ERROR - [JSC_UNDEFINED_VARIABLE] variable h$ghcjsbn_readInteger is undeclared
  8833| return h$ghcjsbn_readInteger(str);
                   ^^^^^^^^^^^^^^^^^^^^^

all.js:8904:126: ERROR - [JSC_UNDEFINED_VARIABLE] variable a is undeclared
  8904| while(--i&gt;=0) r = (h$c2(h$ghczmprimZCGHCziTypesziZC_con_e, ((h$c1(h$ghczminternalZCGHCziInternalziJSziPrimziJSVal_con_e, (a[i])))), (r)));
                                                                                                                                      ^

all.js:8931:14: ERROR - [JSC_UNDEFINED_VARIABLE] variable ls is undeclared
  8931| for(var i=ls-k;i&gt;=0;i-=k) r = (h$c2(h$ghczmprimZCGHCziTypesziZC_con_e, ((h$c1(h$ghczminternalZCGHCziInternalziJSziPrimziJSVal_con_e, (x.substr(i,i+k))))), (r)));
                      ^^

all.js:19980:0: ERROR - [JSC_UNDEFINED_VARIABLE] variable h$stg_absentErrorzh is undeclared
  19980| h$stg_absentErrorzh(b,c);
         ^^^^^^^^^^^^^^^^^^^

all.js:19986:0: ERROR - [JSC_UNDEFINED_VARIABLE] variable h$stg_paniczh is undeclared
  19986| h$stg_paniczh(h$ghczmprimZCGHCziPrimziPaniczilvl_1,h$ghczmprimZCGHCziPrimziPaniczilvl_2);
         ^^^^^^^^^^^^^

6 error(s), 80 warning(s)

```

UPDATE:  
It seems like I have gotten it to work now thanks to the old wiki that @alexfmpe linked.  
I used the additional option `--jscomp_off=checkVars` and then it completed successfully.  
So my command was: `$ npx google-closure-compiler --js=all.js --jscomp_off=checkVars --externs all.externs.js --js_output_file=out.min.js --compilation_level ADVANCED_OPTIMIZATIONS --language_in UNSTABLE`

The file is now 3.3 MiB. And from my initial testing everything seems to still work as expected!

But I assume I should also use the following two additional options: `--isolation_mode=IIFE --assume_function_wrapper` as documented in the old wiki and its also used in the Makefile mentioned before.

---

_[View the full topic](https://discourse.haskell.org/t/ghc-js-backend-improve-compiled-size/12098)._
