Fork me on GitHub
#clojurescript
<
2023-11-06
>
itaied13:11:53

Can I require an edn file like I can import a JSON in JS? I'm running in the browser using shadow-cljs

Chris McCormick13:11:20

Maybe inline it with shadow.resource/inline.

(:require [shadow.resource :as rc])

(read-string (rc/inline "myfile.edn"))
Where myfile.edn is inside src or elsewhere in classpath.

itaied13:11:58

(def x (rc/inline "./app.edn"))
--------------^-----------------------------------------------------------------
Encountered error when macroexpanding shadow.resource/inline.
Could not resolve ./app.edn from main at line 13 main.cljs
Both main.cljs and app.edn are in src

thheller13:11:54

in the same folder? I mean is it src/main.cljs and src/app.edn?

thheller13:11:06

could be that it doesn't like non segmented namespaces. your namespaces should have proper structure

thheller13:11:13

so my.app.main or something

thheller13:11:29

just use (rc/inline "/app.edn"), i.e. without the .

itaied13:11:12

great it worked

itaied13:11:30

is that because the ns is main and not segmented?

thheller13:11:05

the logic could be broken for making things relative to the root. not really sure, single segment namespaces are not recommended

Arek18:11:07

Hi, trying to compile cljs project with ShadowCljs (JVM v2.17.8) ends up with

[2023-11-06 20:00:06.888 - WARNING] :shadow.cljs.devtools.server.util/handle-ex - {:msg {:type :start-autobuild}}
NoSuchFieldError ECMASCRIPT_NEXT_IN
        shadow.build.closure/lang-key->lang-mode (closure.clj:80)
        shadow.build.closure/lang-key->lang-mode (closure.clj:79)
        shadow.build.closure/set-options (closure.clj:144)
        shadow.build.closure/set-options (closure.clj:111)
        shadow.build.closure/convert-goog* (closure.clj:2262)
        shadow.build.closure/convert-goog* (closure.clj:2227)
        shadow.build.closure/convert-goog (closure.clj:2406)
        shadow.build.closure/convert-goog (closure.clj:2356)
        shadow.build.compiler/maybe-closure-convert (compiler.clj:1218)
        shadow.build.compiler/maybe-closure-convert (compiler.clj:1211)
        shadow.build.compiler/compile-all (compiler.clj:1453)
        shadow.build.compiler/compile-all (compiler.clj:1330)
The thing is the same project works on my workmates machines. I even made a new (Linux) account and cloned repo to test it there and it works. I removed almost all the stuff from ~/.clojure/deps.edn so it looks like this, but still the same:
{:deps {org.clojure/clojure {:mvn/version "1.11.1"}
        org.clojure/clojurescript {:mvn/version "1.11.121"}}

 :aliases {:nrepl {:extra-deps
                   {nrepl/nrepl {:mvn/version "1.1.0"}
                    cider/cider-nrepl {:mvn/version "0.43.0"}
                    com.kohlschutter.junixsocket/junixsocket-core {:mvn/version "2.3.2"}}
                   :main-opts ["-m" "nrepl.cmdline"
                               "--middleware" "[cider.nrepl/cider-middleware]"]}
           :build {:deps {io.github.clojure/tools.build {:git/tag "v0.9.4" :git/sha "76b78fe"}}
                   :ns-default build}}}
Also I upgraded all versions. Does anyone have any idea what can cause this problem?

vemv18:11:29

Probably a transitive dependency of your project and one of shadow-cljs are overlapping in an incompatible way. It's pretty common for the Google Closure dep. Although that doesn't explain why your workmates don't see the same :thinking_face:

thheller18:11:54

correct, that is a version conflict and an incompatible closure-compiler version

Arek19:11:51

Ok. We had no clojurescript dep in project's deps.edn so shadow was trying to use my global cljs 1.11.x. I just added the latest 1.10.x to deps and it works fine. My workmates probably had installed 1.10 so this is why it worked for them. Thank you for help

phill00:11:04

Uh oh, this sounds very scary. If I omitted something from deps.edn, it might be fulfilled from some unexpected other place? Can I prevent that from happening?

thheller08:11:30

don't use ~/.clojure/deps.edn

🆒 1
thheller08:11:00

or use -Srepro Ignore the ~/.clojure/deps.edn config file as a clj arg, as per clj -h