Welcome! Please see the About page for a little more info on how this works.

+1 vote
in ClojureScript by
{code:title=deps.edn}
{:deps {org.clojure/clojurescript {:mvn/version "1.10.339"}}
 :aliases {:bug {:main-opts ["-m" "cljs.main" "-co" "bug.cljs.edn" "--repl"]}}}


{code:title=bug.cljs.edn}
{:main          bug.core
 :output-dir    "target/js"
 :optimizations :none
 :libs          ["bug/jslib.js"]
 :modules       {:cljs-base {:output-to "target/js/bug.js"}
                 :lazy-loaded {:entries #{bug.wrapper}
                               :output-to "target/js/bug-wrapper.js"}}}


{code:title=src/bug/core.cljs}
(ns bug.core
  (:require [bug.loader :as bug]))

(enable-console-print!)

(bug/load)


{code:title=src/bug/jslib.js}
goog.provide("bug.jslib");

bug.jslib.start = function() {
    console.log("I've been lazy-loaded successfully!")
};


{code:title=src/bug/loader.cljs}
(ns bug.loader
  (:require [cljs.loader :as loader]))

(defn load []
      (loader/load :lazy-loaded
                   (fn []
                       ((resolve 'bug.wrapper/start)))))


{code:title=src/bug/wrapper.cljs}
(ns bug.wrapper
  (:require [bug.jslib :as jslib]
            [cljs.loader :as loader]))

(enable-console-print!)

(defn start []
      (jslib/start))

(loader/set-loaded! :lazy-loaded)


Repro:


$ clj -A:bug
java.io.FileNotFoundException: /private/tmp/cljs-2820/target/js/cljs/loader.js (No such file or directory)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at clojure.java.io$fn__10972.invokeStatic(io.clj:238)
    at clojure.java.io$fn__10972.invoke(io.clj:235)
    at clojure.java.io$fn__10881$G__10874__10888.invoke(io.clj:69)
    at clojure.java.io$fn__10942.invokeStatic(io.clj:165)
    at clojure.java.io$fn__10942.invoke(io.clj:165)
    at clojure.java.io$fn__10894$G__10870__10901.invoke(io.clj:69)
    at clojure.java.io$reader.invokeStatic(io.clj:102)
    at clojure.java.io$reader.doInvoke(io.clj:86)
    at clojure.lang.RestFn.invoke(RestFn.java:410)
    at cljs.repl$load_sources.invokeStatic(repl.cljc:217)
    at cljs.repl$load_sources.invoke(repl.cljc:209)
    at cljs.repl$load_namespace.invokeStatic(repl.cljc:251)
    at cljs.repl$load_namespace.invoke(repl.cljc:233)
    at cljs.repl$load_dependencies$fn__6358.invoke(repl.cljc:259)
    at clojure.core$map$fn__5587.invoke(core.clj:2747)
    at clojure.lang.LazySeq.sval(LazySeq.java:40)
    at clojure.lang.LazySeq.seq(LazySeq.java:49)
    at clojure.lang.RT.seq(RT.java:528)
    at clojure.core$seq__5124.invokeStatic(core.clj:137)
    at clojure.core$apply.invokeStatic(core.clj:652)
    at clojure.core$mapcat.invokeStatic(core.clj:2775)
    at clojure.core$mapcat.doInvoke(core.clj:2775)
    at clojure.lang.RestFn.invoke(RestFn.java:423)
    at cljs.repl$load_dependencies.invokeStatic(repl.cljc:259)
    at cljs.repl$load_dependencies.invoke(repl.cljc:254)
    at cljs.repl$evaluate_form.invokeStatic(repl.cljc:561)
    at cljs.repl$evaluate_form.invoke(repl.cljc:498)
    at cljs.repl$repl_STAR_$fn__6610.invoke(repl.cljc:950)
    at cljs.repl$repl_STAR_$fn__6621$fn__6622.invoke(repl.cljc:987)
    at cljs.repl$repl_STAR_$fn__6621.invoke(repl.cljc:982)
    at cljs.compiler$with_core_cljs.invokeStatic(compiler.cljc:1289)
    at cljs.compiler$with_core_cljs.invoke(compiler.cljc:1278)
    at cljs.repl$repl_STAR_.invokeStatic(repl.cljc:979)
    at cljs.repl$repl_STAR_.invoke(repl.cljc:855)
    at cljs.cli$repl_opt.invokeStatic(cli.clj:305)
    at cljs.cli$repl_opt.invoke(cli.clj:292)
    at cljs.cli$main.invokeStatic(cli.clj:636)
    at cljs.cli$main.doInvoke(cli.clj:625)
    at clojure.lang.RestFn.applyTo(RestFn.java:139)
    at clojure.core$apply.invokeStatic(core.clj:659)
    at clojure.core$apply.invoke(core.clj:652)
    at cljs.main$_main.invokeStatic(main.clj:61)
    at cljs.main$_main.doInvoke(main.clj:52)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.lang.Var.applyTo(Var.java:702)
    at clojure.core$apply.invokeStatic(core.clj:657)
    at clojure.main$main_opt.invokeStatic(main.clj:317)
    at clojure.main$main_opt.invoke(main.clj:313)
    at clojure.main$main.invokeStatic(main.clj:424)
    at clojure.main$main.doInvoke(main.clj:387)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.lang.Var.applyTo(Var.java:702)
    at clojure.main.main(main.java:37)
ClojureScript 1.10.339
cljs.user=>


Indeed when I go into {{target/js/cljs}} I see loader.cljs but not loader.js. It seems like it's not compiled to js for a reason I can't understand.

In the REPL when I try to (require '[trackers.core :as t]) I get the exact same error.

11 Answers

0 votes
by

Comment made by: dnolen

Any chance we can get something minimal without all these outside file references we won't have access to? Thanks.

0 votes
by

Comment made by: djebbz

Here you go https://github.com/DjebbZ/bug-cljs-2820
Bare minimum and bug happens. All instructions in the README.

0 votes
by

Comment made by: mfikes

Updated description with copy of minimal repro (so no GitHub reference necessary).

0 votes
by

Comment made by: djebbz

Thank you Mike, sorry for not having inlined everything necessary from the start.

0 votes
by
_Comment made by: djebbz_

It doesn't seem related to the {{:libs}} option at all, since I tried another variant with no Javascript file. The only changes necessary to the repro case above are:

1. Remove the {{:libs}} option from bug.cljs.edn

{code:title=bug.cljs.edn}
{:main          bug.core
 :output-dir    "target/js"
 :optimizations :none
 :modules       {:cljs-base {:output-to "target/js/bug.js"}
                 :lazy-loaded {:entries #{bug.wrapper}
                               :output-to "target/js/bug-wrapper.js"}}}


2. Change bug.wrapper.cljs so that it doesn't call the js namespace but directly prints to the console

{code:title=bug.wrapper.cljs}
(ns bug.wrapper
  (:require [cljs.loader :as loader]))

(enable-console-print!)

(defn start []
      (println "I, cljs, have been lazy-loaded successfully"))

(loader/set-loaded! :lazy-loaded)


I did run {{rm -rf target/ .cpcache/}} before re-running {{clj -A:bug}}. Hence, unless I misunderstood something, I think code-splitting is broken?
0 votes
by

Comment made by: djebbz

Sorry I did not specify the output with the changes: it's exactly the same as before (no loader.js file)

0 votes
by
_Comment made by: djebbz_

Sorry to bump the issue, and maybe pollute the tracker and maybe waste your time.

It seems the initial problem is solved with the latest commit on master to date. There is a "target/js/cljs/loader.js" file that looks legit. To reproduce use the following deps.edn file (only cljs coordinate changed)

{code:title=deps.edn}
{:deps {org.clojure/clojurescript {:git/url "https://github.com/clojure/clojurescript" :sha "6eedd0a08c49f7b0d4dcb30977b2fb38c90577bd"}}
 :aliases {:bug {:main-opts ["-m" "cljs.main" "-co" "bug.cljs.edn" "--repl"]}}}
 

But there are 2 other problems now.

1. The generated synthetic main.js file is broken. Here's the content from my browser's devtools for the main.js file:

{code:title=main.js}
var CLOSURE_UNCOMPILED_DEFINES = {"clojure.browser.repl.PORT":9000,"clojure.browser.repl.HOST":"localhost","goog.json.USE_NATIVE_JSON":true};
var CLOSURE_NO_DEPS = true; document.write('<script src="target/js/goog/base.js"></script>');
document.write('<script src="target/js/goog/deps.js"></script>');
/cljs_deps.js"></script>'); // <--- BROKEN !
document.write('<script src="target/js/brepl_deps.js"></script>'); document.write('<script>goog.require("clojure.browser.repl.preload");</script>');
 

So the browser complains with "Uncaught SyntaxError: Invalid regular expression flags" (of course).

2. The repl doesn't launch in the terminal. Maybe related to the first problem?

Should I open another issue for this problem? I haven't investigated enough if it's related to this particular config or a general problem with Cljs.
0 votes
by

Comment made by: djebbz

I haven't bisected the git history (yet, time permitting) to identify which commit seemed to fix the original problem, neither to identify when the new reported problem happened.

0 votes
by

Comment made by: djebbz

I'm sorry, you can forget about my 2 previous comments. With the latest ClojureScript master (:sha "6eedd0a08c49f7b0d4dcb30977b2fb38c90577bd") the original problem of the loader.js file not found still exists. I don't know how I managed to get past this problem. I realize that I didn't delete the target/ and .cpcache/ directories when I just tried.

So my offer to help still exists. With time permitting, I'll just point my repro project to a local version of CLJS with :local/root and try understanding the problem.

0 votes
by
_Comment made by: djebbz_

I managed to get past the missing loader.js file problem and reproduce the broken main.js  problem. It happens when I add the "--compile" option. Below is the complete deps.edn file that reproduce the problem, the rest doesn't change at all.

{code:title=deps.edn}
{:deps {org.clojure/clojurescript {:local/root "/home/djebbz/code/etc/clojurescript"}}
 :aliases {:bug {:main-opts ["-m" "cljs.main" "-co" "bug.cljs.edn" "--compile" "--repl"]}}}


Is it expected that I need to add the "--compile" flag whereas I already add some compile option with the "-co" flag? The bug.cljs.edn file already mentions a :main namespace.
0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2820 (reported by alex+import)
...