'a is undefined' when compiling a cljs prj with an NPM module under :prod profile

220 Views Asked by At

I followed this howto: http://blob.tomerweller.com/reagent-import-react-components-from-npm and it worked great. I even managed to use one of my own NPM module on top of this example app of re-frame: https://github.com/Day8/re-frame/tree/master/examples/simple/

Starting the resulting app with:

lein clean && lein figwheel

everything works ok, but when I do:

lein do clean, with-profile prod compile

I get a TypeError: a is undefined. Any idea to fix this?

Let me provide you with the code: the bad commit is here, while both :dev and :prod profiles work OK at this just previous commit.

Update: I managed to fix the compiled version like this (see the commit):

  return d.c?d.c(c,v,w):d.call(null,c,v,w)}}(G,r,b,c,d,e)),I=dw(G);rf.b?: […]
  };w.b=v;w.c=f;return w}()}(c,d,e,f))};hf.b(ow,ik);hf.b(ow,bp);hf.b(ow,To); […]
  function nx(a){var b=window.deps["react-mathjax"],
-    c=window.deps.clubexpr.kf;
+    c=window.deps.clubexpr.renderLispAsLaTeX;
  return new U(null,3,5,V,[Vj,b.Context,new U(null,4,null)}
  function Wv(){return function(a){return function(){return new U(null,6,5,V,[…]

This seems to me a compilation misconfiguration or bug.

Update 2: my code compiles OK if I set :optimizations to :simple (was :advanced). See the cljs compiler doc about this option.

Thanks.

1

There are 1 best solutions below

3
On

The code that is failing is here.

It looks like you might need to provide externs for clubexpr, so that the Closure Compiler knows not to rewrite renderLispAsLatex as kf. When compiling under :simple, the Closure Compiler doesn't rewrite function names, so this problem wouldn't show up.

As a side note, you probably shouldn't use aget to get objects from the window, aget is designed for array access only. To get objects, you should use goog.object/get. See this post on Checked Array Access for more info on this.