Fork me on GitHub

Top-level requires are only for REPL/scripts and not for compiled targets, is that correct?


not really


though that was the main driver for making it work


but we spent some time to make sure it would work for compilation in general - so if something is amiss file a ticket


things to be aware of


any file w/o an ns is cljs.user


var clashes are possible


(and expected really)


I tried loading cljs files using (load-file) once is a self hosted target and it is impossible as there is no way to do this properly as it seems the files depend on some analyzer data.


load-file probably isn't the right way to load files, self-hosted or otherwise. But maybe I'm misunderstanding what you mean.


Let me explain what i was trying to do, i was trying to create a scriptable browser in cljs+electron, the idea was to have a self hosted cljs in the browser as well as the electron runtime that starts the main window. So that user configurable scripts can be put into say a home directory ~/.mybrowser/init.cljs somewhat like emacs. Now i used load-file because this path is not a part on the src/ load path of the rest of the program. But still it turned out to be difficult because even if somehow i got the string content of the file the context in which self hosted cljs runs is different from the main application it may not have access to many of the libs of the main program. èval-str`isnt equivalent to js èval` it seems to be not running in the same context or doesnt have access to any other namespace.


@dnolen the documentation only speaks about REPL. Would you advice against separate requires if you can avoid them, e.g for mark them as ‘side effecting’ for tooling? We’re trying to come up with some kind of way to signal that to tooling and some people have been doing it like this in JVM Clojure


E.g clean-ns would leave such requires alone


@metacritical ok, but far as I can tell all those problems are solveable w/ the current set of tools in cljs.js - the caveat being that is pretty advanced stuff


@borkdude I'm just not following?


even in Clojure user.clj is general a dev time thing


so what problem are you actually trying to solve here?


I’ll reply when I’m not on mobile


@metacritical walking through all of it isn't practical wrt. time to explain - you might want to look at existing efforts - lumo, planck, etc.


@dnolen Will try and have a look thanks!


I believe borkdude is working on a linter, and he wants to warn users when a namespace has been required (through the ns form usually), but hasn’t been used. however, some namespaces are required only for their side effects on load. so he is trying to figure out a way to let users hint at the linter (and other tooling that might be built) that a require is done only for side effects


I believe near the bottom of the above issue, someone suggests using top-level (require ...) for side-effects instead of the (ns ... (:require ...)) and there were some questions about it’s usability outside of the REPL


I’m back now. @lilactown is correct. so per the suggested style you would have something like:

(ns foo (:require [clojure.set :as set]))
(require '[cljsjs.foobar]) ;; only used for foreign lib loading
(set/union #{} #{})
so tooling would not remove cljsjs.foobar even though it’s not explicitly used in the code of the namespace


I was wondering if this would always work, as the docs hint that require in CLJS is used for the REPL


^ @dnolen hope it’s clearer now


@borkdude I don't think this landed in any formal documentation but ns followed by require is not consistent with this post


@mfikes in his foo.cljs file, what would be the namespace name - there doesn’t seem to be an ns form


also, I’m not asking anyone to implement this, just want to know if it’s supposed to work, or brittle in any way and therefore it may not be recommended


In his foo.cljs file, the namespace would be cljs.user


right, because there is no ns form yet. in the REPL, when you do this, the namespace name is set by the previous (ns ...) expression


(This is just from rule 6 in António's post)


per his post it’s or/or/or


I tried this out:

;; src/nstest/core.cljs:

(ns nstest.core)

(require '[clojure.set :as set])

(defn foo [] (set/union #{} #{}))

(defn -main [& args]
  (println (foo)))

(set! *main-cli-fn* -main)

;; compile with:
;; clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}}}' -m cljs.main -re node -c nstest.core
node out/main.js
goog.require could not find: nstest.core
That seems enough evidence that it isn’t supported


thank for the link to Antonio’s blog @mfikes, very helpful


@borkdude I thought that worked? But that wasn't the real thrust of what we were supporting since it's not meaningful to do it that way


I tried it and it seems it didn’t, unless I did something wrong.


hey @thheller I just saw you provided guidance on clojureverse for implementing webcomponents in cljs. Just wanted to say THANK YOU! I've been looking for that info for a while and it all sort of came together with your reply about the super constructor this morning! for anyone interested in webcomponents, bookmark this thread for later:


I've been doing clojure for a while, but I'm a newbie at clojurescript. Is it possible to build libraries, callable from javascript, specifically node.js, using clojurescript? I've found lots of references to calling javascript from clojurescript, but not the other way around. I found this:, but I don't want to build an executable script - I want to build a library. So, any pointers, suggestions, comments as to why this is a bad idea, etc. are welcome.

Chris O’Donnell22:06:37

Haven't looked at how it works, but I know datascript does this:


Interesting - I'll give their build a look. I'm building a query language implementation, too. The system is implemented as a parser service, written in antlr, node, and express, which produces a simplified parse tree to pass to the interpreter service (it makes more sense than it sounds like, given the language) which will be written in clojure. The front end of the whole thing (which at this point isn't much more than an input and output window linked by the parser service) is being written in clojurescript and reagent. The reason I want build a clojure library is that I'd like to do constant-folding in the parser service, and to get similar semantics, I'd like to use the same code in the evaluators on both sides of the fence. Since some of the semantics of the primitives in the evaluator are complex, dealing with imprecise timing relations, I'd prefer to write it in .cljx.


it might be worth looking at cljc its whats support better nowadays