re-natal icon indicating copy to clipboard operation
re-natal copied to clipboard

:foreign-libs use leads to goog.nodeGlobalRequire issue

Open mfikes opened this issue 6 years ago • 3 comments

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.

mfikes avatar Oct 20 '18 13:10 mfikes

thanks @mfikes for reporting it, let me post a screenshot to subscribe to that issue:

screen shot 2018-10-20 at 5 02 55 pm

igrishaev avatar Oct 20 '18 14:10 igrishaev

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?

mharju avatar Jan 17 '19 06:01 mharju

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

mfikes avatar Jul 24 '19 01:07 mfikes