Fork me on GitHub
#shadow-cljs
<
2020-02-07
>
pre03:02:18

This is taken from an example app with aws amplify + shadow https://dev.to/royalaid/cljs-s-aws-amplify-4f25 src/app.cljs:

(:require ["@aws-amplify/api" :refer [graphqlOperation] :default API]                                                                                                                                                                                                                                 
            ["@aws-amplify/pubsub" :default PubSub]                                                                                                                                                                                                                                                   
            ["/graphql/mutations" :refer [createTodo]]                                                                                                                                                                                                                                                
            ["/graphql/queries" :refer [listTodos]]                                                                                                                                                                                                                                                   
            ["/graphql/subscriptions" :refer [onCreateTodo]]                                                                                                                                                                                                                                          
            ["/aws-exports" :default awsconfig] ;; Important Diff, no period                                                                                                                                                                                                                          
            [applied-science.js-interop :as j])                                                                                                                                                                                                                                                      
                                                        
Local directory has src/graphql generated and corresponding js files (queries, mutations). The following require throws an error: The required JS dependency "/graphql/mutations" is not available, it was required by "app.cljs". What am I missing?

dottedmag08:02:10

@pri Do you have src in :source-paths?

pre21:02:48

yes, i'm an experienced clojure engineer, but haven't used a mixed cljs/js project with shadow yet

g7s10:02:26

I introduced another dependency and I have a REPL open. Is there any way to reload the dependencies without restarting the REPL? The only thing I found is (shadow/reload-deps!) but it returns :shadow.cljs.devtools.api/standalone-only and is doing nothing

thheller10:02:18

CLJS dependencies require a restart

g7s10:02:51

cool thanks

kenny19:02:08

I just ran npx shadow-cljs node-repl from the terminal and received this message. It appears to indicate I need to install the ws module. This is all that's in my package.json

{
  "name": "spec1-select",
  "dependencies": {},
  "devDependencies": {
    "karma": "4.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cljs-test": "0.1.0",
    "shadow-cljs": "2.8.83"
  }
}

kenny19:02:27

This does not exit the JVM. I have to ctrl+c which the results in this message getting printed continuously

cljs.user=> Failed to read: clojure.lang.ExceptionInfo: Input/output error {:type :reader-exception, :line 1, :column 1, :file "repl-input.cljs"}
That will only stop when I ctrl+c again.

kenny19:02:44

Adding "ws": "7.2.1" to my package.json fixes this. Seems strange that this is required.

kenny19:02:55

Still ctrl+c'ing after adding the ws module results in continuous printing of that Failed to read message.

thheller20:02:16

ws normally is a dependecy of shadow-cljs so it should be installed. not sure why it wouldn't be

thheller20:02:40

the repl process doesn't really expect the node process to crash on startup so I guess it doesn't handle that correctly

ro620:02:25

I'm working on a browser extension (using {:target :chrome-extension}) and trying to set up some functions in a user.cljc file to help me switch between the REPLs hosted by the background and content scripts. I have the logic figured out (using (shadow/repl-runtime-select ...)) , but the UX still isn't clean for a few reasons: 1. The base Clojure REPL loads shadow.user instead of my user ns 2. Shadow doesn't seem to load my user ns on initial compile into either the CLJ or CLJS REPLs (perhaps because nothing depends on it?) Is there a way to configure Shadow to load my user ns automatically in all of the REPLs (the default Clojure behavior)? Can I query the CLJS runtime from within? (similarly to the way shadow.cljs.devtools.api works from the base Clojure REPL)

thheller20:02:51

you can set :devtools {:repl-init-ns some.ns} per build

👍 8
ro620:02:18

Thanks for the quick response, that mostly made it a lot better, but there's still an issue. Once I've switched into the CLJS REPL for the first time, when I try to run a fn from my user ns, I get this error

(enter-content-script-repl)
no source by provide: user
{:provide user}
ExceptionInfo: no source by provide: user
	shadow.build.data/get-source-id-by-provide (data.clj:184)
	shadow.build.data/get-source-id-by-provide (data.clj:181)
	shadow.build.data/get-source-by-provide (data.clj:187)
	shadow.build.data/get-source-by-provide (data.clj:186)
	shadow.cljs.repl/repl-compile/fn--14867/fn--14868 (repl.clj:453)
	shadow.cljs.repl/repl-compile/fn--14867 (repl.clj:429)
	shadow.cljs.repl/repl-compile (repl.clj:427)
	shadow.cljs.repl/repl-compile (repl.clj:424)
	shadow.cljs.repl/process-read-result (repl.clj:515)
	shadow.cljs.repl/process-read-result (repl.clj:491)
	shadow.cljs.devtools.server.worker.impl/do-repl-rpc (impl.clj:844)
	shadow.cljs.devtools.server.worker.impl/do-repl-rpc (impl.clj:798)
	shadow.cljs.devtools.server.worker.impl/eval15787/fn--15788 (impl.clj:879)
	clojure.lang.MultiFn.invoke (MultiFn.java:234)
	shadow.cljs.devtools.server.util/server-thread/fn--15324/fn--15325/fn--15333 (util.clj:285)
	shadow.cljs.devtools.server.util/server-thread/fn--15324/fn--15325 (util.clj:284)
	shadow.cljs.devtools.server.util/server-thread/fn--15324 (util.clj:257)
	java.lang.Thread.run (Thread.java:830)

ro620:02:12

enter-content-script-repl is a CLJC fn and has a CLJS portion that works fine once I manually load the ns.

thheller20:02:12

hmm yeah I think there was a bug when :init-ns isn't part of the actual build

thheller20:02:35

you can maybe add :devtools {:preloads [the-repl-init-ns] :init-ns the-repl-init-ns}

thheller20:02:45

that forces it to be compiled as part of the ubild

ro620:02:53

Cool, trying.

thheller20:02:56

I thought I had fixed that issue but maybe I didn;t

ro621:02:57

I'm on 2.8.83

ro621:02:29

Guess that is the latest release. Sometimes I have trouble keeping up, which is a good problem to have 🙂

ro621:02:16

The :preloads trick worked. Everything's nice and clean now. Would you like me to file an issue that :repl-init-ns should imply that the ns gets loaded?

ro621:02:59

Nevermind, found the existing. I'll pile on that one. https://github.com/thheller/shadow-cljs/issues/474

thheller20:02:43

for the CLJ repl you can configure :repl {:init-ns user} at the top level

jmckitrick21:02:20

So I’m back again, trying to get my project to compile with shadow and then produce an uberjar. At some point running the uberjar task, the payload built by shadow in target/cljsbuild is being deleted. I’ve disabled :clean-targets in my project file, but it’s still happening.

jmckitrick21:02:58

What’s the best way to have shadow build the app and put it in the right place for the uberjar task to find it and the app to serve it?

thheller21:02:32

I don't know what your uberjar setup is so kinda hard to answer

thheller21:02:05

typically people use :output-dir "resources/public/js so something like that in the shadow-cljs build config

thheller21:02:23

and lein by default will package resources into the uberjar (or configured via :resources-paths)

jmckitrick21:02:29

The project is generated by luminus, so those defaults should apply.

jmckitrick21:02:41

Ok, so I’ll start looking at ‘resources’

thheller21:02:04

note that is only the classpath root it will package

thheller21:02:22

so whenever things are served it would be /js/main.js or whatever your files are named

thheller21:02:21

as far as lein is concerned its just files in a dir. it doesn't need to know anything else about CLJS

jmckitrick21:02:34

That’s what I thought as well.

thheller21:02:37

and as far as shadow-cljs is concerned its just writing files into a dir, it doesn't care about lein either

jmckitrick22:02:31

Maybe lein is running a clean before uberjar, and that’s what’s blowing away the js files.

jmckitrick22:02:45

Well, that was it. All I did was change ‘output-dir’ per your suggestion.

thheller22:02:08

lein does clean if you tell it to clean yes

jmckitrick22:02:29

I didn’t explicitly.

thheller22:02:42

just clean manually if you have to via rm -rf resources/public/js && shadow-cljs release app && lein uberjar

thheller22:02:19

also don't put CLJS in uberjars if you can help it ... 😛

jmckitrick22:02:01

Definitely not! lol

pre23:02:34

With (:require ["/graphql/mutations"]) why does shadow throw a The required JS dependency "/graphql/mutations" is not available ..." when the source path is set to src and it contains src/graphql/mutations.js?