We're updating the issue view to help you get more done. 

:foreign-libs with module conversion does not works properly if it is used form deps.cljs

Description

When :foreign-libs is used for consume commonjs (or amd) modules from clojurescript using the `deps.cljs` mechanism, an unexpected "internal compiler error" is raised. When the same configuration is attached on the build script, everything works as expected.

Simple way to reproduce that, create sample directory tree:

1 2 3 4 5 6 mkdir tmp; cd tmp; mkdir -p src/testapp mkdir -p src/vendor touch src/testapp/core.cljs touch src/vendor/greeter.js

Download the latest compiler or copy the recently build one from master:

1 wget https://github.com/clojure/clojurescript/releases/download/r1.9.36/cljs.jar

Create the sample cljs file:

1 2 3 4 5 6 7 8 9 10 11 12 ;; tmp/src/testapp/core.cljs (ns testapp.core (:require [cljs.nodejs :as nodejs] [greeter.core :as g])) (nodejs/enable-util-print!) (defn -main [& args] (println (g/sayHello "Ciri"))) (set! *main-cli-fn* -main)

Create the sample commonjs module:

1 2 3 4 5 "use strict"; exports.sayHello = function(name) { return `Hello ${name}!`; };

Create the build script (that works):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 ;; tmp/build.clj (require '[cljs.build.api :as b]) (b/build "src" {:main 'testapp.core :output-to "out/main.js" :output-dir "out" :target :nodejs :language-in :ecmascript6 :language-out :ecmascript5 :foreign-libs [{:file "vendor/greeter.js" :module-type :commonjs :provides ["greeter.core"]}] :verbose true})

And compile this using the following command:

1 java -cp cljs.jar:src clojure.main build.clj

This will generate successfully the final artifact that can be successufully executed with node:

1 2 node out/main.js # => "Hello Ciri!"

But, if you remove the `:foreign-libs` from the build script and create a new `src/deps.cljs` file
with the following content:

1 2 3 {:foreign-libs [{:file "vendor/greeter.js" :module-type :commonjs :provides ["greeter.core"]}]}

And try compile it:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 $ java -cp cljs.jar:src clojure.main build.clj Copying jar:file:/home/niwi/tmp/cljs.jar!/cljs/core.cljs to out/cljs/core.cljs Reading analysis cache for jar:file:/home/niwi/tmp/cljs.jar!/cljs/core.cljs Compiling out/cljs/core.cljs Using cached cljs.core out/cljs/core.cljs Copying jar:file:/home/niwi/tmp/cljs.jar!/cljs/nodejs.cljs to out/cljs/nodejs.cljs Compiling out/cljs/nodejs.cljs Compiling src/testapp/core.cljs Copying jar:file:/home/niwi/tmp/cljs.jar!/cljs/nodejs.cljs to out/cljs/nodejs.cljs Copying jar:file:/home/niwi/tmp/cljs.jar!/cljs/nodejscli.cljs to out/cljs/nodejscli.cljs Copying jar:file:/home/niwi/tmp/cljs.jar!/goog/base.js to out/goog/base.js Copying jar:file:/home/niwi/tmp/cljs.jar!/goog/string/string.js to out/goog/string/string.js Copying jar:file:/home/niwi/tmp/cljs.jar!/goog/object/object.js to out/goog/object/object.js Copying jar:file:/home/niwi/tmp/cljs.jar!/goog/string/stringbuffer.js to out/goog/string/stringbuffer.js Copying jar:file:/home/niwi/tmp/cljs.jar!/goog/debug/error.js to out/goog/debug/error.js Copying jar:file:/home/niwi/tmp/cljs.jar!/goog/dom/nodetype.js to out/goog/dom/nodetype.js Copying jar:file:/home/niwi/tmp/cljs.jar!/goog/asserts/asserts.js to out/goog/asserts/asserts.js Copying jar:file:/home/niwi/tmp/cljs.jar!/goog/array/array.js to out/goog/array/array.js Copying file:/home/niwi/tmp/src/vendor/greeter.js to out/greeter.js Exception in thread "main" java.lang.RuntimeException: INTERNAL COMPILER ERROR. Please report this problem. null Node(SCRIPT): vendor/greeter.js:1:0 [source unknown] Parent: NULL, compiling:(/home/niwi/tmp/build.clj:3:1) at clojure.lang.Compiler.load(Compiler.java:7391) at clojure.lang.Compiler.loadFile(Compiler.java:7317) at clojure.main$load_script.invokeStatic(main.clj:275) at clojure.main$script_opt.invokeStatic(main.clj:335) at clojure.main$script_opt.invoke(main.clj:330) at clojure.main$main.invokeStatic(main.clj:421) at clojure.main$main.doInvoke(main.clj:384) at clojure.lang.RestFn.invoke(RestFn.java:408) at clojure.lang.Var.invoke(Var.java:379) at clojure.lang.AFn.applyToHelper(AFn.java:154) at clojure.lang.Var.applyTo(Var.java:700) at clojure.main.main(main.java:37) Caused by: java.lang.RuntimeException: INTERNAL COMPILER ERROR. Please report this problem. [...]

Environment

Linux, openjdk8

Status

Assignee

Unassigned

Reporter

import

Approval

None

Patch

Code

Affects versions

1.9.76
1.9.36

Priority

Minor