nervous-systems / cljs-lambda

Utilities around deploying Clojurescript functions to AWS Lambda
The Unlicense
311 stars 34 forks source link

Fix ReferenceError exception by passing :output-wrapper true to the compiler #79

Closed alessandrod closed 7 years ago

alessandrod commented 7 years ago

When invoking the clojurescript compiler directly with :optimizations :advanced, also set :output-wrapper true. lein-cljsbuild does this too, and without it ^:exported symbols don't get exported correctly.

See #78.

alessandrod commented 7 years ago

I think the bug boils down to this:

alessandro@june:/tmp$ cat a.js
console.log("this === global", this === global);
(function() {
console.log("this === global", this === global);
})()
alessandro@june:/tmp$ node a.js
this === global false
this === global true

Looking at the output of :optimizations :advanced, it seems (the output is really horrible) like Google Closure expects this to be the global object, which without :output-wrapper true is instead {}.

Meh.

moea commented 7 years ago

Awesome, thanks - I wasn't aware you were using the Serverless template.