Fork me on GitHub
#shadow-cljs
<
2022-05-11
>
bmaddy01:05:17

Is there some kind of clean step or way to force recompiling the classpath (like -Sforce for tools.deps) in shadow-cljs? I didn't see one in the docs. I ask because I'm sometimes compiling my code in a docker container and sometimes locally. I end up getting errors like this when compiling in the container: > $ yarn shadow-cljs release main > ... > shadow-cljs - starting via "clojure" > Error: Could not find or load main class clojure.main > Caused by: java.lang.ClassNotFoundException: clojure.main > error Command failed with exit code 1. Deleting the .cpcache directory fixes it, but I'm wondering if there is other stuff I should be deleting.

thheller06:05:08

@bmaddy you can just use the clojure/clj commands directly. shadow-cljs release app is identical to clj <aliases+whatever> -M -m shadow.cljs.devtools.cli release app

thheller06:05:02

otherwise no, deleting .cpcache is enough

bmaddy16:05:49

Great, thank you!

pez06:05:04

I'm trying to use the npm module fast-glob, but am failing to import it properly. Trying this:

(:require ["fast-glob" :as fast-glob :default fg :refer [sync]] ...)
I get module$node_modules$fast_glob$out$index is not defined whichever of those symbols (`fast-glob`, fg, sync) I try to evaluate, and also if I try to call any of them. I do see that this file has been produced:
out/js/cljs-runtime/module$node_modules$fast_glob$out$index.js
I've tried restarting the watcher, and even wiped .shadow-cljs/ and out/ to no avail.

pez06:05:30

Ideally I want to use the Async API of fast-glob: https://github.com/mrmlnc/fast-glob#asynchronous

const fg = require('fast-glob');

const entries = await fg(['.editorconfig', '**/index.js'], { dot: true });

// ['.editorconfig', 'services/index.js']
But that's a luxury problem right now. 😃

thheller06:05:36

sounds like a node only package maybe? not going to work in a browser setting?

pez06:05:37

Oh, sorry, forgot. It's an electron project, #joyride to be precise. My config looks like so:

{:deps true
 :builds
 {:extension {:target :node-library
              :js-options {:js-provider :shadow
                           :keep-native-requires true
                           :keep-as-require #{"vscode"}}
              :compiler-options {:infer-externs :auto}
              :output-dir "out/js"
              :output-to "out/joyride.js"
              :exports {:activate joyride.extension/activate}
              :devtools {:before-load-async joyride.extension/before
                         :after-load joyride.extension/after}}}}

thheller06:05:04

:keep-as-require #{"vscode" "fast-glob"}

🙏 1
thheller06:05:09

can't look into why it doesn't work right now. but node only packages pretty commonly do node specific stuff that shadow-cljs doesn't support.

pez07:05:30

Adding it to :keep-as-require worked. Thanks! ❤️ shadow even hot-reloaded the config. 🤯

pez13:05:50

Running into troubles with the packaged extension now instead, @thheller:

mainThreadExtensionService.ts:111 Activating extension 'betterthantomorrow.joyride' failed: Cannot find module 'fast-glob'
Require stack:
- /Users/pez/.vscode/extensions/betterthantomorrow.joyride-0.0.9-52-get-started-content-6099ecbf/out/joyride.js
- /Users/pez/.vscode/extensions/betterthantomorrow.joyride-0.0.9-52-get-started-content-6099ecbf/extension.js
- /Applications/Visual Studio 
- /Applications/Visual Studio 
- /Applications/Visual Studio .
$onExtensionActivationError @ mainThreadExtensionService.ts:111
Is there a way I can make shadow bundle it into the release build?

pez16:05:31

I got around this by using fdir instead of fast-glob. That one doesn't need to be included in the :keep-as-require set.

thheller18:05:33

is there a way for me to easily test this?

thheller18:05:15

fast-glob would need to be bundled. I assumed that would be handled in some way already by electron.

pez18:05:27

With Calva we use webpack to bundle things together. We might need to go there with #joyride too. But for now shadow does all the work.

pez18:05:09

Electron is maybe the wrong way to describe the project. It's a VS Code extension, and VS Code is Electron.

thheller19:05:09

yeah, just would assume that the default tooling for this would include npm packages in some way

pez19:05:05

I should be able to create a small example with fast-glob.

danieroux15:05:29

Checking understanding. shadow-cljs supports:

["semantic-ui-react$Confirm" :as Confirm]
It does not support:
[semantic-ui-react$Confirm :as Confirm]

danieroux15:05:37

I am not missing anything?

thheller18:05:33

@danie both should be fine?

danieroux18:05:43

Huh. Sorry, I slipped up somewhere. It now indeed works, as one presumes it did all along!

danieroux18:05:07

Ok, got it broken again for me. This branch passes: https://github.com/danieroux/semantic-ui-wrapper/tree/cljs [:workspaces] Build completed. (1105 files, 0 compiled, 0 warnings, 14.66s) This one does not: https://github.com/danieroux/semantic-ui-wrapper/tree/shadow-cljs-build-issues

[:workspaces] Build failure:
Multiple files failed to compile.
aborted par-compile, [:shadow.build.classpath/resource "fulcrologic/semantic_ui/workspaces/dropdown.cljs"] still waiting for #{com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-item com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-divider com.fulcrologic.semantic-ui.elements.icon.ui-icon com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-menu}
{:aborted [:shadow.build.classpath/resource "fulcrologic/semantic_ui/workspaces/dropdown.cljs"], :pending #{com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-item com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-divider com.fulcrologic.semantic-ui.elements.icon.ui-icon com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-menu}}
ExceptionInfo: aborted par-compile, [:shadow.build.classpath/resource "fulcrologic/semantic_ui/workspaces/dropdown.cljs"] still waiting for #{com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-item com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-divider com.fulcrologic.semantic-ui.elements.icon.ui-icon com.fulcrologic.semantic-ui.modules.dropdown.ui-dropdown-menu}

danieroux18:05:31

The difference is how those requires gets generated.

thheller18:05:02

well the string is absolutely preferred yes. can't say why it fails, will try with a smaller example 😉

danieroux18:05:46

As long as you get the same error, and I don't have local gremlins 😊

thheller07:05:03

should be fixed in 2.19.0

Nundrum18:05:53

I'm getting errors when starting npx shadow-cljs server

[2022-05-11 14:22:58.929 - WARNING] :shadow.cljs.devtools.server.nrepl/middleware-fail - {:sym cider.nrepl/cider-middleware}
Note: The following stack trace applies to the reader or compiler, your code was not executed. 
CompilerException Syntax error compiling at (cider/nrepl.clj:1:1). #:clojure.error{:phase :compile-syntax-check, :line 1, :column 1, :source "cider/nrepl.clj"}
I didn't think cider was built in. But there it is. I'll put my shadow-cljs config in the thread. My /.clojure/deps.edn is empty. There isn't a config in /.cljs or ~/.nrepl. What else could I be missing?

Nundrum18:05:26

shadow-cljs.edn:

{:builds
 {:app {:asset-path "/js"
        :modules {:main {:init-fn app.core/main}}
        :output-dir "public/js"
        :target :browser}
  :cards {:asset-path "/js"
          :modules {:main {:init-fn app.cards/main}}
          :compiler-options {:devcards true}
          :output-dir "public/js"
          :target :browser}
  :test {:ns-regexp "app.cards"
         :output-to "out/test.js"
         :target :node-test}
  :e2e {:ns-regexp "e2e.*"
        :output-to "out/e2e.js"
        :target :node-test}}
 :dependencies [[reagent "0.8.1"]
                [devcards "0.2.6"]
                [cljs-http "0.1.46"]
               ; [cider/cider-nrepl "0.28.3"]
                ]
 :dev-http {3000 "public"}
 :nrepl {:port 3333}
 :source-paths ["src"]}

thheller19:05:09

what is the full error? and which shadow-cljs version?

Nundrum19:05:47

[2022-05-11 14:22:58.929 - WARNING] :shadow.cljs.devtools.server.nrepl/middleware-fail - {:sym cider.nrepl/cider-middleware}
Note: The following stack trace applies to the reader or compiler, your code was not executed.
CompilerException Syntax error compiling at (cider/nrepl.clj:1:1). #:clojure.error{:phase :compile-syntax-check, :line 1, :column 1, :source "cider/nrepl.clj"}
        clojure.lang.Compiler.load (Compiler.java:7648)
        clojure.lang.RT.loadResourceScript (RT.java:381)
        clojure.lang.RT.loadResourceScript (RT.java:372)
        clojure.lang.RT.load (RT.java:459)
        clojure.lang.RT.load (RT.java:424)
        clojure.core/load/fn--6839 (core.clj:6126)
        clojure.core/load (core.clj:6125)
        clojure.core/load (core.clj:6109)
        clojure.core/load-one (core.clj:5908)
        clojure.core/load-one (core.clj:5903)
        clojure.core/load-lib/fn--6780 (core.clj:5948)
        clojure.core/load-lib (core.clj:5947)
Caused by:
IllegalAccessError with-session-classloader does not exist
        clojure.core/refer (core.clj:4249)
        clojure.core/refer (core.clj:4217)
        clojure.core/apply (core.clj:667)
        clojure.core/load-lib (core.clj:5966)
        clojure.core/load-lib (core.clj:5928)
        clojure.core/apply (core.clj:667)
        clojure.core/load-libs (core.clj:5985)
        clojure.core/load-libs (core.clj:5969)
        clojure.core/apply (core.clj:667)
        clojure.core/require (core.clj:6007)
        clojure.core/require (core.clj:6007)
        cider.nrepl/eval7083/loading--6721--auto----7084 (nrepl.clj:1)
[2022-05-11 14:22:59.291 - WARNING] TCP Port 3000 in use.
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.10.22 running at 
shadow-cljs - nREPL server started on port 3333

Nundrum19:05:53

So looks like 2.10.22

thheller19:05:19

try upgrading. that is rather old.

Nundrum19:05:47

Huh. I just npm installed it a few days ago.

thheller19:05:31

just check the version in package.json?

thheller19:05:43

do you use npx shadow-cljs to run?

thheller19:05:06

you might just have a global install that is out of date?

Nundrum19:05:03

Hrrrm an npm update fix it! Good catch.

Nundrum19:05:10

I had used npx create-cljs-app to create the project

thheller19:05:15

hmm maybe that is hardcoded to the really old version? can't say

thheller19:05:58

yeah, it is hardcoded to a really old verison. I opened an issue, hope they fix it

Nundrum20:05:03

Thanks. I was trying to figure out how it worked, but you beat me to it.