Fork me on GitHub
#shadow-cljs
<
2019-04-08
>
manuel10:04:43

Hi everybody. Is there a way to reference a local project as a dependency in shadow-cljs.edn? Like :local/root does in deps.edn, I mean.

thheller10:04:35

only if you use deps.edn

thheller10:04:03

you could just add the :source-paths manually too but nothing like :local/root without deps.edn

manuel10:04:21

I see, thank you

hoopes14:04:31

Hi, in my shadow-cljs.edn file i have :source-paths [ "dev" "src" "test" ] - in the dev directory, i have company/repl.cljs, and add :repl-init-ns company.repl - when i then load the page, i get a 500 error with the message clojure.lang.ExceptionInfo: no output for id: [:shadow.build.classpath/resource "company/repl.cljs"] {:resource-id [:shadow.build.classpath/resource "company/repl.cljs"]. I've also tried just putting user.cljs in there, but get the same error. Is there something obvious I'm missing? to start the repl, i'm running shadow-cljs cljs-repl my-project-id.

thheller14:04:07

something seems off about your error

thheller14:04:15

500 error doesn't make sense?

thheller14:04:24

you are running shadow-cljs watch your-build I presume?

thheller14:04:45

and that completed successfully?

hoopes14:04:19

yes, and that's where the error is being printed, in the watch terminal

hoopes14:04:52

Apr 08, 2019 10:16:42 AM io.undertow.server.Connectors executeRootHandler
ERROR: UT005071: Undertow request failed HttpServerExchange{ POST /worker/files/sif/4ef2910a-fa9c-4a38-b142-fcbfbc831193/34c60217-4ac5-46a3-b75c-7567c23309ca request {Accept=[*/*], Accept-Language=[en-US,en;q=0.9], Accept-Encoding=[gzip, deflate], Origin=[], User-Agent=[Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36], Connection=[keep-alive], Content-Length=[427], content-type=[application/edn; charset=UTF-8], Referer=[], Host=[]} response {Cache-Control=[private, no-cache]}}
clojure.lang.ExceptionInfo: no output for id: [:shadow.build.classpath/resource "company/repl.cljs"] {:resource-id [:shadow.build.classpath/resource "company/repl.cljs"]}

thheller14:04:52

oh. the company.repl namespace probably isn't included by any other means right?

hoopes14:04:55

full error

thheller14:04:14

try adding it to :preloads

hoopes14:04:15

ah, no - i thought the source-path would somehow imply it was required

thheller14:04:36

I guess I don't account for :repl-init-ns not being part of the build

thheller14:04:39

probably should

thheller14:04:56

for now just add it to :devtools {:preloads [company.repl]} for your build

hoopes14:04:02

that was it, it's working now

hoopes14:04:07

thanks!!!!!

hoopes14:04:12

really appreciate it

mss14:04:32

very weird error that I’m having trouble debugging. trying to get a bare bones shadow-cljs compilation working with my app via lein. have my :depencencies and :source-paths set in my project.clj and :lein true set at the top level of my shadow-cljs config. receiving the error Exception in thread "main" Syntax error compiling . at (shadow/build/closure.clj:67:5).. I’ve stripped down everything in my project.clj to be absolutely bare bones with just dependencies and src-paths, yet still encountering this error

mss14:04:53

just declaring everything in shadow cljs and not using lein works for getting my js built. working with a clj/cljs codebase tho and would prefer to not have to duplicate my dependencies declaration for the different platforms

thheller14:04:56

check lein deps :tree

thheller14:04:18

there should be a [com.google.javascript/closure-compiler-unshaded "v20190325"] dependency

thheller14:04:51

if you still have a cljsbuild or figwheel plugin running they might be adding older versions of that dep

mss14:04:07

yep that’s exactly the conflict

Stefan16:04:47

The blog post I wrote about my adventures with shadow-cljs and react native navigation was published today: https://040code.github.io/2019/04/02/react-native-navigation-and-clojurescript/. (Here you are @haiyuan.vinurs.) Thanks again @thheller!!

👍 12
rastandy17:04:18

hello everyone

rastandy17:04:56

I’v just started to use shadow-cljs, pretty nice tool, thanks to everyone involved.

rastandy17:04:44

I’m hitting a problem in my project config right now, I’m really stuck trying to understand why it’s not working. My project file looks like this:

rastandy17:04:38

{:source-paths [“src”] :dependencies [[cider/cider-nrepl “0.21.0"]] :builds {:app {:target :node-script :output-to “target/main.js” :main server.main/main! :devtools {:after-load server.main/reload!} :js-options {:resolve {“oauth2" {:target :file :file “/src/js/oauth2.js”}}}}}}

rastandy17:04:19

the problem here is the :js-options keyword, the compiler continues to tell me this:

rastandy17:04:37

[:app] Build failure: Wrong number of args (4) passed to: shadow.build.npm/js-resource-for-file

thheller17:04:56

why are you doing that?

rastandy17:04:47

@thheller good question. Because I wasn’t able to import some functions from a js file I have in my project, so I tried to specify this file in the project config

thheller17:04:27

so you want to include that file directly in your project? it is not an override for something within node_modules?

rastandy17:04:34

My import doesn’t work:

rastandy17:04:34

(ns server.google-sheet (:require [“fs” :as fs] [“googleapis” :as g] [“oauth2” :as auth :refer (listFiles oAuth2Client)] [clojure.pprint :as pp] [promesa.core :as p]))

rastandy17:04:51

@thheller no, it’s not an overwrite

thheller17:04:52

ok yeah then you should skip the :resolve config completely

thheller17:04:06

and just require the file directly

rastandy17:04:32

ok, but then importing functions from the js file results in the imported symbols being null

thheller17:04:10

what module format do you use? import/export ESM or require/module.exports commonjs?

thheller17:04:20

the .js file that is

rastandy17:04:37

the module.exports flavour

thheller17:04:47

ok that should work fine then?

rastandy17:04:22

I think so, but hey, at least you directed me on the right track again, I was fighting with the wrong configuration settings

lilactown17:04:44

@rastandy try logging auth and see what's in there

thheller17:04:45

as a quick test make sure the file is on the classpath

rastandy17:04:45

I will check the .js file correctness

thheller17:04:54

then fire up shadow-cljs browser-repl

thheller17:04:12

then (require '["/path/to/file.js" :as x])

rastandy17:04:57

uhm I’m using cider-connect-cljs, it works but right now it’s not finding the .js file

rastandy17:04:04

let me check again the path

thheller17:04:56

with your :source-paths ["src"] and the file at src/js/oauth2.js it would be (require '["/js/oauth2.js" :as x])

thheller17:04:49

(js/console.dir x) is sometimes better than (prn x) so maybe try that too

rastandy17:04:13

I’ve included the js file in my server.main namespace

rastandy17:04:42

the file is loaded from the app and some code is executed, I see the output in the stdout

rastandy17:04:54

but when importing, the ns is null

thheller17:04:03

can you please test why I asked?

thheller17:04:10

skip cider or anything else

rastandy17:04:11

(ns server.google-sheet (:require [“fs” :as fs] [“googleapis” :as g] [“./oauth2” :as auth :refer (listFiles oAuth2Client)] [clojure.pprint :as pp] [promesa.core :as p])) (prn auth)

thheller17:04:19

don't use prn then

rastandy17:04:24

(prn auth) is null

thheller17:04:40

and the file actually has exports?

rastandy17:04:46

oh ok, will skip cider

rastandy17:04:02

yes: module.exports = { authorize, listFiles, oAuth2Client };

thheller17:04:11

can try shadow-cljs node-repl since this is node stuff

thheller17:04:58

just want to eliminate all other factors and that is the quickest way to do it

rastandy17:04:10

I’m not able to change namespace in the node-repl 😞

rastandy17:04:48

sorry forget that

thheller17:04:50

don't change the namespace

thheller17:04:52

just require

rastandy17:04:53

it was a typo

thheller17:04:37

literally just shadow-cljs node-repl then (require '["/server/oauth2.js" :as x]) (js/console.dir x) nothing else

rastandy17:04:40

yes it loads the file, I can see the output from some statements in the js file

thheller17:04:49

and what is x?

rastandy17:04:19

#js {:default #js {:authorize #object[Function], :listFiles #object[Function], :oAuth2Client #object[OAuth2Client [object Object]]}}

lilactown17:04:40

looks like it's loading as esm

thheller17:04:58

ah right ... closure is rewriting it "incorrectly"

thheller17:04:21

probably best to just switch the file to use export { authorize, listFiles, oAuth2Client } instead.

rastandy17:04:29

I’m not that into JS modules…

thheller17:04:46

does it matter for this file? is anyone else using it?

rastandy17:04:02

no, only me

thheller17:04:16

well that is the quick and easy fix I can offer

thheller17:04:44

the other way is [“./oauth2” :default oauth] and then oauth/listFiles etc

rastandy17:04:50

Ok, but does that imply something else?

thheller17:04:00

no doesn't imply anything else

thheller17:04:39

its just the annoying situation in that the JS world cannot decide on how to do ESM->CommonJS interop

rastandy17:04:45

I made the change in the file: export { authorize, listFiles, oAuth2Client };

thheller17:04:51

and the closure compiler only supports strict mode currently

rastandy17:04:54

now when requiring the module I get:

thheller17:04:02

which means commonjs files only get a default export

rastandy17:04:06

[:result {:type :repl/error, :ex #error { :cause “closure errors” :data {:tag :shadow.build.closure/errors, :errors [{:resource-name “server/oauth2.js”, :source-name “server/oauth2.js”, :line 93, :column 0, :msg “A file cannot be both a CommonJS module and an ES6 module.“}]}

thheller17:04:25

did you remove the module.exports?

thheller17:04:32

can't have both

thheller17:04:41

or whatever else is in line 93

rastandy17:04:01

line 93 is this:

rastandy17:04:01

export { authorize, listFiles, oAuth2Client };

thheller17:04:20

and is there a require or exports or module.exports reference before that?

thheller17:04:42

closure already decided to treat that file as commonjs before it gets to line 93

rastandy17:04:59

gosh! Yes there are requires at the top of the file, sorry

rastandy17:04:19

I’m pretty lost in JS modules land

thheller17:04:30

hmm hang on ...

thheller17:04:46

something odd is happening here

thheller17:04:05

because commonjs files on the classpath that have require should not be rewritten by closure

thheller17:04:21

which version are you on?

rastandy17:04:02

shadow-cljs - config: /Users/arusso/Development/clojurescript/ask-scopus/shadow-cljs.edn cli version: 2.8.26 node: v11.13.0 shadow-cljs - server version: 2.8.26 running at http://localhost:9630

thheller17:04:51

alright there seems to be a bug

thheller17:04:59

where node targets are treated differently than browser one

rastandy17:04:10

sorry @thheller maybe it’s better to report with complete files

thheller17:04:23

I have the issue reproduced now so its fine

joshkh17:04:38

totally new to shadow-cljs but i'm excited to start building some node modules! when following the shadow-cljs repo's readme and also with the minimal-shadow-cljs-browser i get the following error in the browser:

bidi.js:276 Uncaught SyntaxError: Invalid regular expression: /[Ö‘-Û¯Ûº-ࣿâ€�-��-�ï¬-ï·¿ï¹°-ﻼ]/: Range out of order in character class
    at new RegExp (<anonymous>)
    at bidi.js:276
any ideas? 🙂

thheller17:04:11

invalid charset used in the HTML

thheller17:04:24

add <meta charset="utf-8"> to your html

joshkh17:04:55

heyo, that did the trick. thanks!

joshkh17:04:23

next question. the repo's readme refers to :node-script as a build target where as the docs refer to :node-library. which one am i after?

thheller17:04:48

depends on what you want to build?

joshkh18:04:35

ah, they're different. got it. i was hoping to play around with cljs and aws nodejs lambdas.

thheller18:04:49

for that you want :node-library

rastandy18:04:39

@thheller thank you very much for you rhelp

joshkh18:04:50

great, thanks! really looking forward to all the great things i've heard about shadow-cljs.

thheller18:04:47

@rastandy I just pushed 2.8.29 that fixes the broken commonjs interop. so it should be working correctly now, no need for :default

mauricio.szabo03:04:53

Ah, that was a bug? I'll upgrade too

thheller18:04:08

might need to undo the changes if you switched to :default

thheller18:04:18

if you switched to import/export that is fine

thheller18:04:18

@joshkh there was a post about shadow-cljs + aws here https://dev.to/royalaid/cljs-s-lambda-697

thheller18:04:21

maybe that helps

rastandy18:04:26

@thheller thank you very much! I’ll confirm if it’s working, thank you again

joshkh19:04:59

> maybe that helps immensely. thanks for sharing!

eoliphant20:04:17

quick question, I’m trying to figure out the best way to handle a ‘lib’ project. Say I have a project with some common fulcro components and it uses a few react libs, then I want to pull it in to my main ui app, via say clojure deps. I guess I’d need to the main app’s package json also include any of the lib projects npm dependencies?

thheller20:04:41

you can include a deps.cljs file with {:npm-deps {"whatever" "version"}} in the lib

Daniel Hines21:04:09

I may just be misunderstanding things, but it seems like when I run shadow-cljs watch app, and open my browser, then connect via a CIDER repl, that there are two distinct contexts. For example, I have an atom defined with defonce - in the browser, it has one value, but at the REPL, it ahs another. Is there a way to unify these two contexts?

richiardiandrea04:04:59

The atom should be contain the same because you are eval-ing code in the same runtime...unless your REPL and your Chrome tools are talking to different runtimes like Thomas suggested.

thheller21:04:46

do you open the correct REPL?

thheller21:04:07

I don't know much about cider sorry but shadow-cljs cljs-repl app would give you the REPL into the browser