Uploaded image for project: 'ClojureScript'
  1. CLJS-1682

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Completed
    • Affects versions: 1.9.76, 1.9.36
    • Fix versions: None
    • Environment:

      Linux, openjdk8

    • Patch:
      Code

      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:

      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:

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

      Create the sample cljs file:

      ;; 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:

      "use strict";
      
      exports.sayHello = function(name) {
        return `Hello ${name}!`;
      };
      

      Create the build script (that works):

      ;; 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:

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

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

      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:

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

      And try compile it:

      $ 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.
      
      [...]
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: