Fork me on GitHub
#shadow-cljs
<
2022-02-10
>
agold14:02:27

I am trying to use instaparse in a shadow-cljs project. I have the following in shadow-cljs.edn: :dependencies  [[instaparse "1.4.10"]] The instaparse-1.4.10.jar is present in the appropriate .m2 repository. But shadow-cljs is not finding it. What am I doing wrong?

jkxyz14:02:33

Can you share the error that you're seeing?

agold15:02:29

I found the problem, thanks.

👍 1
dpsutton15:02:29

it is not. cider-jack-in-clj&cljs attempts to use the same process to start two separate repls. This was possible with figwheel. Shadow is a separate process so you cannot start a single lein and then create two repls from it, one clj and one cljs

👌 1
mamapitufo16:02:24

hello, I'm relatively new to ClojureScript and I'm trying to set up tests for a ns that has a couple of functions. I'm using the recommended cljs.test setup from https://clojurescript.org/tools/testing and I can run my tests fine from the REPL using cljs.test/run-tests. I also followed the instructions in https://shadow-cljs.github.io/docs/UsersGuide.html#target-node-test but when I run shadow-cljs compile test on my terminal I get this exception:

shadow-cljs - connected to server
[:test] Compiling ...
NullPointerException: 
        shadow.build.node/configure (node.clj:59)
        shadow.build.node/configure (node.clj:45)
        shadow.build.targets.node-script/configure (node_script.clj:37)

thheller17:02:07

looks like you don't have a :output-to configured in your build config?

p-himik17:02:12

The article at https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html links to https://github.com/mhuebert/shadow-bootstrap-example for a standalone example. But building the :bootstrap build with shadow-cljs 2.17.0 (where originally it was 2.11.7) fails with:

------ ERROR -------------------------------------------------------------------
 File: jar:file:/home/p-himik/.m2/repository/org/clojure/clojurescript/1.10.914/clojurescript-1.10.914.jar!/cljs/js.cljs:9:1
--------------------------------------------------------------------------------
   6 | ;   the terms of this license.
   7 | ;   You must not remove this notice, or any other, from this software.
   8 | 
   9 | (ns cljs.js
-------^------------------------------------------------------------------------
null
The alias env is already used for namespace cljs.env.macros
--------------------------------------------------------------------------------
  10 |   (:refer-clojure :exclude [require eval])
  11 |   (:require-macros [cljs.js :refer [dump-core]]
  12 |                    [cljs.env.macros :as env])
  13 |   (:require [clojure.string :as string]
--------------------------------------------------------------------------------
Presumably because cljs/js.cljs has both [cljs.env.macros :as env] in its :require-macros and [cljs.env :as env] in its :require. Is there a way to fix this?

p-himik17:02:10

Huh, it actually works with 2.16.12 but breaks with 2.17.0.

thheller17:02:44

uh yeah thats a bug

👍 1
thheller17:02:54

I changed something in alias checks because of :as-alias

Joseph Winston18:02:10

Thanks for verifying the bug. I was chasing the same issue earlier.

thheller18:02:37

hmm my check seems to be doing exactly what it is supposed to be doing? how is this ns form valid? it has env as alias for two different namespaces 😛

thheller18:02:48

guess I have to relax that check a bit ...

thheller18:02:44

should be fine in 2.17.1 again

🎉 1
mauricio.szabo20:02:05

Hi, any tips to debug this error?

shadow-cljs: reloading code but no :after-load hooks are configured! 

mauricio.szabo20:02:56

I do have the :after-load hook configured, and I can evaluate the function of the hook, but somehow nothing happens when I save a file. It's a :browser target, but with an Electron host

thheller06:02:06

this is a warning not an error and you fix it exactly as linked above

thheller06:02:39

where do you have :after-load configured? it is much easier to have ^:dev/after-load in the metadata of your code

thheller06:02:01

code that needs to be included in the build naturally. so if you put it in some namespace that is not part of the build it won't trigger

mauricio.szabo16:02:24

I have in both metadata and in :devtools option. None worked

thheller16:02:23

only one is needed

thheller16:02:36

but as I said if the ns isn't included in the build they don't have any effect

thheller16:02:40

is it included in the build?

thheller16:02:50

needs to be required by something in the build (or added via :preloads)

mauricio.szabo16:02:36

This is the config:

{:target :browser
                 :output-dir "static"
                 :asset-path "."
                 :modules {:main {:init-fn cljs.atom.view/start!}}
                 :js-options {
                              :keep-native-requires true}
                              ;:js-provider :require}
                 :devtools {:before-load cljs.atom.view/start
                            :after-load cljs.atom.view/after-load}}

mauricio.szabo16:02:17

cljs.atom.view is in the config, and when I save the file, I see on Electron's console:

shadow-cljs: reloading code but no :after-load hooks are configured! 
browser.cljs:20 shadow-cljs: load JS cljs/atom/view.cljs

mauricio.szabo16:02:55

Both hooks point only to a (println "testing") for now...

thheller16:02:58

they appear to be in the wrong order?

thheller16:02:14

I mean it doesn't make sense to me triggering a start before loading new code?

thheller16:02:23

helps if you show me the code?

thheller16:02:57

oh wait ...

thheller16:02:13

cljs.* is reserved. no hooks in those are discovered or used

mauricio.szabo16:02:24

Yep, that was it! Thanks again, as always! I'm doing something incredibly bizarre with ClojureScript, so I though it was something way more complicated than just the namespace name 😄

ag21:02:36

How do you deal with other watchers, doing some work outside of shadow-cljs? For example, I'm using postcss, and I have an npm script task to compile/watch. I can run it in another shell session, not a problem. But that has a minor annoyance - whenever I make style-related changes, they do not reflect in the browser without a manual refresh. And I think what's happening is that shadow-cljs picks up changes first (when .cljs files with hiccup modified), and npm script process always lagging behind. I thought about maybe using ^:dev/before-load-async, but that's in a file on the browser side. Can I have something similar but in clj, not cljs?

thheller06:02:55

I use a setup using npm-run-all. as for example in this repo using postcss+tailwind

thheller06:02:37

although I only use it to run postcss itself. I run shadow-cljs separately but you could easily run it there too

thheller06:02:57

as for style related changes I added a new hook for that recently that is not in the docs yet

thheller06:02:18

you may just be missing some watch related config if you just have css that isn't getting reloaded in the first place yet

rende1115:02:08

@U05224H0W Hello Tomas, it works not only for css files, right? (I try to reload frontend after changes in .edn resources)

thheller16:02:08

no, thats not supported

rende1110:02:04

@U05224H0W But why? It's not possible in current implementation or needless feature or no time to implement this functionality?

thheller15:02:27

mostly because there are limits to what shadow-cljs can reasonably do. There is no easy way to tell which files you are going to access and tracking all of them might get expensive. dunno what you are doing this code .edn files but maybe this already solves whatever it is https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745

rende1117:02:11

@U05224H0W Thanks for the answer. I use .edn files for translations (i18n) that's why I wanna reload frontend after some changes in them. I think it's a popular case. Isn't it? So you haven't any plans to extend this tracking?

thheller18:02:13

I have no plans but if you setup a demo repo I might consider it

thheller18:02:28

nobody else ever asked for this. so can't be that popular

ag21:02:18

Reading through the docs, perhaps I should look into the "build hooks"?

ag22:02:36

Yup, it does look exactly what I'm looking for. I apologize for the noise.