JavaScript code using module-processing (CJS/ES6) can require ClojureScript namespaces using e.g. {{goog.require("name.space")}} or {{import * from "goog:name.space";}}. But currently Closure optimization fails if this namespace is only used by JS modules and not other Cljs namespaces.
This happens when {{build}} {{source}} is single file, or when {{:optimization}} and {{:main}} are set, as in that case build entrypoint is the {{:main}} file.
Problem is that in build pipeline, no new Cljs sources are added to build after JS files from {{:libs}} are added (including files from module processing):
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L2809-L2819
With {{:optimization :none}} this doesn't show error during build, but there would be error during runtime about missing module. With optimizations, Closure will throw error about missing module.
;; build.clj
(require 'cljs.build.api)
(cljs.build.api/build
"src"
{:main 'hello.core
:output-to "target/main.js"
:output-dir "target/main.out"
:asset-path "main.out"
:optimizations :simple
:foreign-libs [{:file "src"
:module-type :es6}]})
;; or "src/hello/core.cljs" as source and :optimization :one
;; src/hello/core.cljs
(ns hello.core (:require [hello.es-module :refer [greet]]))
(greet "test")
;; src/hello/say.cljs
(ns hello.say)
(defn ^:export it [m]
(str "Hello, " m))
;; src/hello/es_module.js
import it from "goog:hello.say";
export var greet = function(m) {
document.write(hello.say.it(m));
};
Closure error:
Mar 27, 2018 7:02:07 PM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 1 error(s), 0 warning(s)
ERROR: JSC_MISSING_PROVIDE_ERROR. required "hello.say" namespace never provided at /home/juho/tmp/cljs-in-js-in-cljs/target/main.out/src/hello/es_module.js line 2 : 0
Exception in thread "main" java.lang.Exception: Closure compilation failed, compiling:(/home/juho/tmp/cljs-in-js-in-cljs/build.clj:3:1)