0

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.

Daniel Compton
  • 13,878
  • 4
  • 40
  • 60
Gra
  • 1,542
  • 14
  • 28

1 Answers1

2

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.

Daniel Compton
  • 13,878
  • 4
  • 40
  • 60
  • Thanks for your answer and this very recent precious piece of information. However I'm not familiar with externs and didn't manage to use the online tool. Is my module correctly structured? https://clubexpressions.github.io/node-clubexpr/index.js – Gra Jul 25 '17 at 05:51
  • Not sure sorry, there's lots of info at https://github.com/cljsjs/packages/wiki/Creating-Externs. – Daniel Compton Jul 26 '17 at 06:06
  • OK, not much time to give it a try right now but I'll keep you update and vote/accept your answer accordingly. Thanks! – Gra Jul 27 '17 at 07:13