Fork me on GitHub
#shadow-cljs
<
2023-03-02
>
Jakub Šťastný03:03:10

Hey guys. I have an issue configuring ESM modules.

npx shadow-cljs compile core
shadow-cljs - config: /Users/jakub/Documents/Projects/bizmentor/cljs-calc/shadow-cljs.edn
[:core] Compiling ...
The required namespace "calc.profit-and-loss" is not available.
This is my shadow-cljs.edn config:
{:source-paths ["src"]
 :dependencies []
 :builds
 {:core
  {:target :esm
   :output-dir "output"
   :modules
   {:demo {:exports
           {salesGrowthRate calc.profit-and-loss/sales-growth-rate}}}}}}
The file src/calc/profit-and-loss.cljs:
(ns calc.profit-and-loss)

(defn sales-growth-rate [] "ret")
What am I doing wrong? I read the manual and I thought this is how it should work, but seems like I'm wrong(?)

Braden Shepherdson03:03:38

huh, that looks like it should work from the docs. try adding :entries [calc.profit-and-loss] to the :demo module? it shouldn't be necessary

Jakub Šťastný03:03:22

Hey @UCY0GT0QM, thanks. Strangely adding the entries thing doesn't help.

Jakub Šťastný03:03:18

I'm on the latest shadow-cljs 2.21.0 and shadow-cljs-jar is 1.3.4, just installed it.

Braden Shepherdson03:03:33

double-check the file paths, that's there's not like src/main or something throwing it off. other thing to try is break the syntax in the file, so it'll error earlier. that'll prove it's getting the right file.

Jakub Šťastný03:03:39

There's actually only that one file

tree src
src
└── calc
    └── profit-and-loss.cljs

2 directories, 1 file

Jakub Šťastný03:03:19

I do keep wondering whether I'm doing something stupid, but I don't see anything.

Jakub Šťastný03:03:48

Yep I AM doing something stupid.

Jakub Šťastný03:03:00

clj -A:src
Clojure 1.11.1
user=> (require 'calc.profit-and-loss)
Execution error (FileNotFoundException) at user/eval1 (REPL:1).
Could not locate calc/profit_and_loss__init.class, calc/profit_and_loss.clj or calc/profit_and_loss.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

Jakub Šťastný03:03:30

Renaming src/calc/profit-and-loss.cljs to src/calc/profit_and_loss.cljs did the trick.

Jakub Šťastný03:03:38

I'm new to Clojure...

Braden Shepherdson04:03:07

ah, I should have spotted that. glad you've got it working.

🙏 2
Arnaud Plumez11:03:26

Hello! I ran into this error when executing "npx shadow-cljs watch app" : Execution error (AssertionError) at shadow.undertow/eval19463$fn (undertow.clj:145). Assert failed: (.exists root-dir) Do you know which directory "root-dir" is supposed to be ? I did not found anything related to this issue

thheller11:03:05

could be a :dev-http root that doesn't exist?

thheller11:03:22

ie :dev-http {3000 "public"} with public not existing? or an older :http-root in :devtools in the build config?

Ryan15:03:39

I’m looking at a build report for an app and I’m noticing some classes in the src bundle are way larger in optimized size than the size of the source file itself.. is that number the size of the src file and its required files as well?

thheller15:03:06

classes? example?

thheller15:03:48

if you are talking about cljs code then they'll often be larger yes? especially if you use things like core.async which can generate absurd amounts of code in some cases

Ryan15:03:34

Yes its cljs code, aha, ok. Just looking for ways to slim down the bundle size. Also a little confused by I’m seeing re-frame-10x stuff in the build report, I think something is configured incorrectly in my setup

thheller15:03:46

:release
  {:build-options
   {:ns-aliases
    {day8.re-frame.tracing day8.re-frame.tracing-stubs}}}
being the important bit

Ryan15:03:00

Going to compare them now. Thanks for pointing out the important bit 🙂

thheller15:03:28

otherwise you can mouse over the specific source line in the build report. it should tell you what required it

Ryan15:03:24

Wow that’s slick!

Ryan15:03:54

My current best guess is the large bundle size is timezone and date formatting code in the mystery larger classes.. heck like 10% of my bundle size is historical timezone data -_-

thheller15:03:28

what do you mean by classes?

Ryan15:03:55

sorry, I just mean source files. I don’t know why I’m calling them classes

Ryan15:03:27

The perils of learning on Java is that somehow sourcefile = class in my brain 😅

Ryan15:03:31

Awesome I definitely want to look into code splitting this.

thheller15:03:08

any macro can for that matter

Maris16:03:57

:builds {:main {:target :browser :output-dir "resources/public/cljs" :asset-path ""

Maris16:03:42

Is it possible to have different :asset-path for release build ?

thheller16:03:13

@maris.orbidans https://shadow-cljs.github.io/docs/UsersGuide.html#_release_specific_vs_development_configuration although :asset-path usually isn't relevant much in release builds. also why do you have the full URL in there? /cljs not enough?

👍 2
Maris17:03:28

I copied it from lein-cljsbuild configuration

Maris21:03:13

/cljs is not enough

Jakub Šťastný21:03:49

Hey. Has anyone seen these: Could not set npm package requirements. Error getting response at for package "shadow-cljs": An npm specifier not found in cache: "shadow-cljs", --cached-only is specified.? (Details in the thread.)

Jakub Šťastný21:03:29

I have a project on the latest shadow-cljs with :target :esm and I'm getting this code within deno repl when I load the generated code into it.

Jakub Šťastný21:03:02

It's rather annoying, I'm hoping to get rid off it, but I'm not understanding where is it coming from.

Maris23:03:14

npm cache clean --force doesnt help ?

thheller05:03:38

I have not done any testing with deno in a long time, so there might be issues

thheller06:03:12

although I'm not sure why deno is even trying to load shadow-cljs? there is no runtime dependency for it, so it shouldn't load it to begin with?

thheller06:03:24

maybe you need to move it into devDependencies in cause you haven't?