re-natal
re-natal copied to clipboard
:foreign-libs use leads to goog.nodeGlobalRequire issue
If you use :foreign-libs
you will encounter an issue with goog.nodeGlobalRequire is not a function
that is evidently related to :target :nodejs
introduced with 0.9.0.
Repro:
src/aaa.js
:
function AAA() {
return 42;
}
Add to your compiler options:
:foreign-libs [{:file "src/aaa.js"
:provides ["aaa"]}]
Bring up the app and a REPL with lein figwheel ios
and then repro with
ios:cljs.user=> (require 'aaa)
#object[TypeError TypeError: goog.nodeGlobalRequire is not a function. (In 'goog.nodeGlobalRequire(file)', 'goog.nodeGlobalRequire' is undefined)]
cljs$core$load_file
eval code
eval@[native code]
figwheel$client$utils$eval_helper
nil
This goes away if you comment the :target :nodejs
from the compiler options.
thanks @mfikes for reporting it, let me post a screenshot to subscribe to that issue:

Bumped to the same issue. The target: nodejs
was added in the commit saying it fixes :closure-defines
and :preloads
.
To what extent do we need the target: nodejs
to accomplish this, specifically the :closure-defines
-part. I'm just thinking would it be safe to just remove the target: nodejs
from the compiler defs as @mfikes suggested or should this issue be delt with in another way?
Yeah, it seems that, while :target :nodejs
provides an easy solution to some issues, it puts the compiler into the wrong mode for other things.
In this particular case it causes the compiler to take the wrong branch here.
You can see that if the compiler took the other branch, things would work by, for the foreign lib described in this issue's description, doing this
ios:cljs.user=> (require 'aaa)
#object[TypeError TypeError: goog.nodeGlobalRequire is not a function. (In 'goog.nodeGlobalRequire(file)', 'goog.nodeGlobalRequire' is undefined)]
cljs$core$load_file
eval code
eval@[native code]
figwheel$client$utils$eval_helper
ios:cljs.user=> (goog/require "aaa")
nil
ios:cljs.user=> (js/AAA)
42