【问题标题】:'a is undefined' when compiling a cljs prj with an NPM module under :prod profile在 :prod 配置文件下使用 NPM 模块编译 cljs prj 时出现“a is undefined”
【发布时间】:2017-07-19 21:26:35
【问题描述】:

我遵循了这个方法:http://blob.tomerweller.com/reagent-import-react-components-from-npm,效果很好。我什至设法在这个 re-frame 示例应用程序之上使用了我自己的 NPM 模块之一:https://github.com/Day8/re-frame/tree/master/examples/simple/

使用以下命令启动生成的应用程序:

lein clean && lein figwheel

一切正常,但当我这样做时:

lein do clean, with-profile prod compile

我收到了TypeError: a is undefined。有什么办法解决这个问题吗?

让我给你提供代码:错误提交是here, 而:dev:prod 配置文件都可以正常工作at this just previous commit

更新:我设法修复了这样的编译版本(参见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,[…]

在我看来这是编译错误或错误。

更新 2:如果我将 :optimizations 设置为 :simple(原为 :advanced),我的代码编译正常。见the cljs compiler doc about this option

谢谢。

【问题讨论】:

    标签: compilation clojurescript cljsbuild


    【解决方案1】:

    失败的代码是here

    看起来您可能需要为 clubexpr 提供 externs,以便闭包编译器知道不要将 renderLispAsLatex 重写为 kf。在 :simple 下编译时,闭包编译器不会重写函数名,因此不会出现此问题。

    附带说明,您可能不应该使用aget 从窗口中获取对象,aget 仅用于数组访问。要获取对象,您应该使用goog.object/get。有关更多信息,请参阅Checked Array Access 上的这篇文章。

    【讨论】:

    猜你喜欢
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2018-08-11
    • 1970-01-01
    相关资源
    最近更新 更多