Fork me on GitHub
#shadow-cljs
<
2019-11-13
>
raf07:11:32

for info, my shadow-cljs.edn looks so:

raf07:11:47

{:source-paths ["src/dev" "src/main" "src/functions" "src/tools" "src/test"] :dependencies [[binaryage/devtools "0.9.10"] [reagent "0.8.1" :exclusions [cljsjs/react]] [re-frame "0.10.9" :exclusions [cljsjs/react]] ; [day8.re-frame/http-fx "v0.2.0"] [secretary "1.2.3"] [cljs-bean "1.5.0"] ;;https://github.com/mfikes/cljs-bean [cider/cider-nrepl "0.22.4"] [testdouble/clojurescript.csv "0.4.5"] ] ; :nrepl {:port 8777} :builds {:app {:target :browser :output-dir "public/js" :asset-path "/js" :modules {:app {:init-fn project.core/init :preloads [devtools.preload]}} :devtools {:http-root "public" :http-port 8000}} :browser-test {:target :browser-test :ns-regexp "-test$" :runner-ns shadow.test.browser :test-dir "tests/browser-test" :devtools {:http-root "target/browser-test" :http-port 8290}} :karma-test {:target :karma :ns-regexp "-test$" :output-to "tests/karma-test.js"} :functions {:target :node-library :output-to "functions/cljs-libs.js" :exports-var project.cloud-functions/declaration} :tools {:target :node-script :output-to "tools/tools.js" :main project.tools/main}}}

thheller11:11:54

@raf I'm not sure what is going on. can you please post a regular github issue so I don't forget looking into it?

raf11:11:59

@thheller sure, I will do that! thanks for looking at it 🙂

sooheon12:11:27

When loading NPM packages the shadow way (i.e. (:require ["foo" :as foo])) I’m getting a spec error trying to load it into a repl:

Syntax error macroexpanding clojure.core/ns at (src/workspaces/app/demo_ws.cljs:1:1).
-- Syntax error -------------------

  (... (:require
        [com.fulcrologic.fulcro.components :as fp]
        [nubank.workspaces.core :as ws]
        [nubank.workspaces.card-types.fulcro3 :as ct.fulcro]
        [com.fulcrologic.fulcro.mutations :as fm]
        [com.fulcrologic.fulcro.dom :as dom]
        ["reakit" :as rk]))
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

has extra input

-- Relevant specs -------

:clojure.core.specs.alpha/ns-form:
  (clojure.spec.alpha/cat
   :ns-name
   clojure.core/simple-symbol?
   :docstring
   (clojure.spec.alpha/? clojure.core/string?)
   :attr-map
   (clojure.spec.alpha/? clojure.core/map?)
   :ns-clauses
   :clojure.core.specs.alpha/ns-clauses)

-------------------------
Detected 1 error

sooheon12:11:46

Seems like it’s because clojure does not expect strings in there. Is this expected?

thheller12:11:51

looks like you are trying to eval CLJS in a CLJ REPL

sooheon12:11:18

I’m pretty sure this is after running (shadow/repl :main)

sooheon12:11:26

And the cursive repl window cljs is selected.

thheller12:11:30

try (js/alert "foo")

thheller12:11:44

if it complains about js namespace then you are in a CLJ REPL

sooheon12:11:01

Ah thanks, I must have messed up repl state somewhere. Restarting everything and making sure i”m in cljs repl fixed it

vinurs12:11:15

how to require

import Storage from 'react-native-storage';
in cljs, i use [“react-native-storage” :default Storage], but the browser output
shadow-cljs - failed to load module$node_modules$react_native_storage$lib$storage_cjs
shadow.js.jsRequire @ js.js:74
shadow.js.require @ js.js:100
eval @ /js/compiled/cljs-runtime/core.js:6
goog.globalEval @ app.js:836
env.evalLoad @ app.js:2216
(anonymous) @ app.js:2901

thheller12:11:45

that doesn't look like a react-native app?

thheller12:11:27

what is the actual error though? this just tells you WHY failed to load, not why. the why is a different error?

vinurs12:11:51

this library also can used in web

thheller12:11:23

well what is the error then? looks like it doesn't

vinurs12:11:49

i just require it, and then output the message

thheller12:11:03

yes but there should be MORE errors. not just that one

vinurs12:11:19

(ns core
  (:require [reagent.core :as r]
            [starter.browser]
            [utils.login]
            ["react-native-storage" :default Storage]
            [pages.dashboard.questionnaire]))


(defn ^:export init
  "auto init"
  []
  (let []
    (prn "thit is cljs init" ))
  )

thheller12:11:24

regeneratorRuntime is not defined is the actual error

thheller12:11:56

I can't remember how to fix that. need to include some "regenerator/runtime" package or so manually

thheller12:11:06

its some babel bs

vinurs12:11:19

i install regenerator-runtime, and require it, ok now, thanks

sooheon12:11:50

@thheller there is of course nothing to be done for symbol resolution in cursive (or emacs) using shadow-style imports, correct? when people develop with js-land deps, there’s no code knowledge/goto/navigation?

thheller12:11:18

not that I'm aware of

sooheon12:11:06

Do you know why loading the ns form might be returning twice?

thheller13:11:28

probably not filtering events correctly. the ns form evaluated at the REPL has multiple effects

thheller13:11:35

each effect has a return value

thheller13:11:45

in this case first it is loading the async dependencies

thheller13:11:48

then doing the JS stuff

Michael Mackenzie13:11:58

I can't seem to reload namespaces in the REPL in my clojurescript app. Here's what I do (after running (shadow/repl :app) to enter in to the CLJS repl):

(use 'getfluentspanish.dom :reload)
Error in phase :compilation
Only [lib.ns :only (names)] and optionally `:rename {from to}` specs supported in :use / :use-macros; offending spec: [getfluentspanish.dom] at line 1 cljs/user.cljs

Michael Mackenzie13:11:14

it seems like namespaces just work way differently in the cljs repl

Michael Mackenzie13:11:25

*ns* doesn't work either

thheller13:11:31

they work very differently yes

Michael Mackenzie13:11:38

is there a guide anywhere?

thheller13:11:46

(require '[the.ns :as x] :reload) should work

thheller13:11:56

use is generally not used in CLJS

Michael Mackenzie13:11:59

it doesn't error out now, but it doesn't seem to reload

thheller13:11:59

now that I think about it .. it isn't even implement in the shadow-cljs REPL 😛

Michael Mackenzie13:11:35

like i add new code, i see that it compiles in the shadow watcher, but the new code isn't available

thheller13:11:37

require should be working though. most people just use the hot-reload though

thheller13:11:59

how are you using it?

Michael Mackenzie13:11:28

(require '[getfluentspanish.dom :as dom] :reload)

Michael Mackenzie13:11:48

added a new function, it's just nil in the repl after

thheller13:11:49

no I mean how do you tell that the new code isn't available?

Michael Mackenzie13:11:12

in repl after reloading: dom/new-function --> nil

Michael Mackenzie13:11:23

not calling it, just evaluating the symbol

Michael Mackenzie13:11:26

and it says it's nil

Michael Mackenzie13:11:42

and changes to another existing function don't show up

Michael Mackenzie13:11:28

i added some log lines and they only show up when i restart the terminal pane i have running lein shadow watch app, refresh the browser tab and restart the repl

thheller13:11:51

uhm I'm confused

thheller13:11:56

you are using hot-reload and the REPL?

thheller13:11:16

if the hot-reload already loads the code you don't need to reload it in the REPL?

Michael Mackenzie13:11:29

well i don't have automatic reloading in the repl

Michael Mackenzie13:11:35

my code recompiles

Michael Mackenzie13:11:50

via lein shadow watch app

Michael Mackenzie13:11:00

i.e. i make changes, the browser reloads my code automatically

thheller13:11:02

and you REPL into app?

Michael Mackenzie13:11:04

but my repl has a stale version

thheller13:11:13

then it will have the updated code

Michael Mackenzie13:11:19

(shadow/repl :app)

thheller13:11:24

(without you doing anything in the REPL)

Michael Mackenzie13:11:43

unfortunately that doesn't seem to be happening

thheller13:11:35

unless you are on some ancient version it kinda can't not happen

Michael Mackenzie13:11:44

let me take a look:

thheller13:11:54

reload loads the namespace

thheller13:11:10

you can just use getfluentspanish.dom/new-function directly in the REPL

Michael Mackenzie13:11:17

[thheller/shadow-cljs "2.8.39" :scope "provided"]

thheller13:11:29

that is rather old

Michael Mackenzie13:11:44

ok i'll try updating

thheller13:11:45

2.8.69 is latest

thheller13:11:59

but pretty sure all of that also worked in that version

Michael Mackenzie13:11:08

bumped the version and still not seeing updates within the repl

Michael Mackenzie14:11:04

it seems like it's only happening with some namespaces

Michael Mackenzie14:11:11

this "dom" namespace is new - i hadn't actually included it elsewhere in the project

Michael Mackenzie14:11:22

i was just manually playing with a new function in the REPL

Michael Mackenzie14:11:16

but for example when i make changes to a namespace that contains a bunch of reagent components that are actually used on the website i'm developing, it: - is updated in the browser - automatically updates in the REPL

Michael Mackenzie14:11:09

maybe it needs to be loaded by the browser to participate in the auto reload functionality?

Michael Mackenzie14:11:35

@thheller that's the problem. once i included in a file loaded by the browser, it started to auto-reload

Filipe Silva16:11:26

I was trying to use devcards with shadow-cljs and finding it a bit hard to find information about that...

Filipe Silva16:11:31

in https://clojurians-log.clojureverse.org/shadow-cljs/2018-04-01 there's some messages from 2018 that say it's mostly just importing devcards with macros, and then set the devcards compiler option to true

Filipe Silva16:11:40

from that starting point the compilation works, but at runtime there's a couple of console warnings and nothings shows on screen

Filipe Silva16:11:44

main.js:2218 failed to load devcards.system.js ReferenceError: React is not defined
    at eval (system.cljs:321)
    at eval (system.cljs:321)
    at eval (<anonymous>)
    at Object.goog.globalEval (main.js:836)
    at Object.env.evalLoad (main.js:2216)
    at main.js:2413
env.evalLoad @ main.js:2218
(anonymous) @ main.js:2413
main.js:2218 failed to load devcards.core.js ReferenceError: React is not defined
    at eval (core.cljs:117)
    at eval (core.cljs:117)
    at eval (<anonymous>)
    at Object.goog.globalEval (main.js:836)
    at Object.env.evalLoad (main.js:2216)
    at main.js:2418

Filipe Silva16:11:41

that namespace belongs to devcards, and points to this function

Filipe Silva16:11:44

(define-react-class DevcardsRoot
  (componentDidMount
   [this]
   (add-watch app-state :renderer-watch (fn [_ _ _ _] (.forceUpdate this))))
  (render [this] (main-template app-state)))

thheller16:11:16

@mike.a.mackenzie yes sorry, hot-reload only reloads sources actually used in the build. for the rest the regular REPL workflow should still work though.

thheller16:11:44

@filipematossilva you can probably get away with importing cljsjs.react. that will create the React global

Filipe Silva16:11:33

should I be using shadow-cljsjs? I saw some references to it in https://github.com/bhauman/devcards/issues/156 but I couldn't figure out how I should use it

thheller16:11:41

the problem you see is that devcards assumes there is a React global, because it was always there when using cljsjs.react

thheller16:11:08

shadow-cljsjs provides shims to emulate that

thheller16:11:32

shadow-cljs already depends on it, so it is always there. no need for you do do anything except add a cljsjs.react require somewhere

Filipe Silva16:11:16

doing so shows an error that seems similar

Filipe Silva16:11:22

system.cljs:334 Uncaught ReferenceError: ReactDOM is not defined
    at Object.devcards$system$renderer [as renderer] (system.cljs:334)
    at eval (system.cljs:458)

thheller16:11:36

cljsjs.react.dom

Filipe Silva16:11:45

ah I tried [cljsjs.react-dom] and that failed, so that's it

thheller16:11:04

I don't know why devcards doesn't depend on those to ensure they exist

Filipe Silva16:11:58

I now see an UI with things that seem from devcards so it looks like it is loaded, will poke around more

Filipe Silva16:11:04

thank you for your help

conan16:11:27

hello, i'm trying to get going with shadow-cljs and Cursive. I'm trying to re-create my old figwheel config, where I had a run configuration that would start figwheel in a Cursive REPL - one click, all in. I've got two problems: 1. I can't figure out how to start a cljs REPL instead of a clj one 2. I can't figure out how to start shadow in my run configuration I'm hoping there's somebody here who uses Cursive and might be able to help?

thheller16:11:48

I use Cursive myself. what was your figwheel setup?

thheller16:11:23

you start a CLJS repl from a CLJ one

thheller16:11:33

so you connect to the CLJ REPL shadow-cljs provides

thheller16:11:43

then (shadow/repl :your-build) and that switches you to CLJS

thheller16:11:12

bind that do a custom REPL keybinding and you have your one click?

conan16:11:22

I use a little script to kick everything off, by passing it in the parameters of a run configuration:

;; 
(require '[figwheel.main.api :as fig])
(fig/start "app")

conan16:11:48

We do a lot of prototyping, which means changing deps. My goal is to restart a CLJS REPL in a single click

thheller16:11:12

and how did you run that script?

conan16:11:18

Currently, I'm only able to run shadow-cljs from a terminal, which means I have to go over there, kill the process, restart and so on

conan16:11:28

That script gets run by the Run Configuration, it's in the parameters field

thheller16:11:57

I mean how do you get a REPL?

thheller16:11:26

ah so just a clojure.main REPL? no nrepl?

conan16:11:29

Sorry, I'm not sure I understand the question. I click the green Run arrow on my build configuration, and Cursive spins one up for me - compiling all the stuff on the way

conan16:11:33

no, no nREPL

conan16:11:52

that's important, as it cuts down on a lot of starting/stopping stuff

thheller16:11:45

(require '[shadow.cljs.devtools.server :as server])
(require '[shadow.cljs.devtools.cli]) ;; if you want to use the shadow-cljs command line tools 
(require '[shadow.cljs.devtools.api :as api])
(server/start!)
(api/watch :app)
(api/repl :app)

conan16:11:58

ah, yes this looks like what I need!

conan17:11:05

just trying it now

thheller17:11:41

don't really recommend running that way but works if you have to 😛

conan17:11:51

out of interest, why not?

thheller17:11:28

takes almost twice as long to start when going through lein

conan17:11:53

I haven't been able to avoid that given that I'm using :lein true in my config

conan17:11:27

I don't want to split out my frontend from my backend, and leiningen seems like the easiest way to keep it all together

thheller17:11:36

do you not use a REPL for your backend?

conan17:11:01

yes, i have a separate run config for that

thheller17:11:47

so you already have 2 separate JVMs anyways

thheller17:11:05

and I assume you have your CLJS dependencies in some extra profile?

thheller17:11:12

:dev or :cljs or so?

conan17:11:09

yes, currently i've put them in the :dev profile, although i actually wasn't sure about that

conan17:11:28

ok, it seems this works. i get a lot of :failed-to-compare errors, but the build still completes successfully

conan17:11:05

looks like something to do with check_npm_versions

conan17:11:17

would it be useful to write some docs to explain this and send a PR?

thheller17:11:01

do you have an example?

conan17:11:40

got over a hundred of 'em

thheller17:11:07

thats not normal

thheller17:11:10

what JVM do you run?

conan17:11:38

Java 1.8.0_222 OpenJDK 64-Bit Server VM

conan17:11:21

sorry that was my ubuntu one. i run cursive in windows

conan17:11:27

windows is this: java version "1.8.0_202" Java(TM) SE Runtime Environment (build 1.8.0_202-b08) Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

thheller17:11:33

seems like nashorn is missing?

conan17:11:12

er, what's that?

conan17:11:51

oh ok, a javascript runtime that runs on the jvm

thheller17:11:54

that seems to return nil? can you check in a CLJ REPL?

thheller17:11:13

yes, a JS engine

thheller17:11:30

(require '[shadow.cljs.devtools.server.npm-deps :as x])

thheller17:11:38

(x/make-engine*)

thheller17:11:48

just to verify that it actually returns nil?

conan17:11:25

yeah i get nil from a clj REPL, although it was started with leiningen

thheller17:11:48

hmm weird. that should definitely work in jdk 1.8

thheller17:11:38

oh is it possible your are just running the JRE? not the JDK?

conan17:11:56

the REPL starts with "C:\Program Files\Java\jdk1.8.0_202\bin\java.exe"

conan17:11:04

so it's a JDK

thheller17:11:14

odd. that should have nashorn

conan17:11:29

yeah it seems to have been introduced with Java 8

thheller17:11:59

never heard of anyone else running into this before

conan17:11:07

ok i'll do some googling. thanks!

conan17:11:12

you've been super helpful

thheller17:11:15

are you sure that is actually the JVM used?

thheller17:11:30

(intellij lets you select others)

conan17:11:48

it's possible that Intellij uses a built-in one, but it prints out that path at the start of the REPL output

thheller17:11:08

strange indeed

conan17:11:07

tell you what though, it's not on my path

conan17:11:09

should it be?

thheller17:11:14

JDK 13 is out btw 😉 jdk8 is like living in the stone age 😛

conan17:11:39

i've always had trouble with clojure and later versions, maybe it's time to give it a bump

conan17:11:44

nashorn seems to be deprecated now though

thheller17:11:45

no running java should be just fine

thheller17:11:02

yeah its deprecated but still here for now 😉

thheller17:11:17

the check ultimately isn't important so its fine

thheller17:11:30

I can probably make it less noisy instead of failing so much 😛

conan17:11:35

i'll keep looking though, because it's very noisy

conan17:11:40

what's it doing, out of interest?

thheller17:11:28

comparing npm package versions to spit out a small warning if they aren't what your packages expected

thheller17:11:25

only uses nashorn because I had no interest in porting this to clojure 😛

thheller17:11:15

don't know what you mean

lilactown21:11:33

has anyone tried hooking up the node-repl to chrome's debugger?

thheller21:11:33

I've done it with :node-script builds

thheller21:11:25

you can do it with (shadow/node-repl {:node-args ["--inspect-brk"]})

lilactown21:11:29

👍 awesome thanks!