This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-09
Channels
- # beginners (205)
- # boot (6)
- # cider (22)
- # cljs-dev (41)
- # cljsrn (4)
- # clojure (97)
- # clojure-dev (61)
- # clojure-greece (40)
- # clojure-italy (8)
- # clojure-russia (16)
- # clojure-spec (18)
- # clojure-uk (34)
- # clojurescript (14)
- # community-development (1)
- # cursive (45)
- # datomic (39)
- # fulcro (66)
- # jobs (2)
- # lein-figwheel (1)
- # lumo (9)
- # off-topic (8)
- # parinfer (98)
- # portkey (8)
- # re-frame (81)
- # reagent (54)
- # remote-jobs (17)
- # ring (2)
- # shadow-cljs (217)
- # spacemacs (32)
- # sql (24)
- # test-check (6)
- # unrepl (73)
- # yada (12)
okay well i can’t get react-flip-move to import: i get nil. i’m pretty sure this is a bug so i’ll open an issue so you have all the context
^ sorry the problem above is that I had put :js-options inside of :devtools (would be super cool if there were warnings about config keys in unexpected places)
@lee.justin.m shadow-cljs indeed always minimizes files and react unfortunately complains about this during development. for shadow-cljs release
it will use their correct production js and not minify the dev version. so the warning is the only problem.
I have created sample repo with both node and browser apps. It is just bare bones. https://github.com/pepe/two-in-shadows
@pepe cool. you can run shadow-cljs watch client server
to watch both builds in one process. no need to use separate processes.
Hi, I use (:require ["qiniu" :as qiniu])
to import a node library to clojurescript in shadow-cljs. But I got stuck when trying to write javascript
var mac = new qiniu.auth.digest.Mac(key1, key2)
in clojurescript. I tried
(def mac (-> (qiniu.auth.digest/Mac access-key secret-key)))
but failed. How should I do this?the aliases created by :as
must always be used as-is. qiniu.auth.digest
is not a valid alias
------ ERROR -------------------------------------------------------------------
File: /Users/chen/repo/memkits/manuscript/src/app/util.cljs:6:11
--------------------------------------------------------------------------------
3 |
4 | (defn focus-text! []
5 | (js/requestAnimationFrame
6 | (fn [] (let [element (.querySelector js/document ".text"), .focus element] ))))
-----------------^--------------------------------------------------------------
Invalid local name: .focus at line 6 app/util.cljs
--------------------------------------------------------------------------------
well @thheller i really appreciate the help. i wanted to say thanks so much for your help and amazing work you are doing. for now, i have to declare defeat. i’ve spent too much time trying to make my project work in cljs and i just have to go back to javascript where i can be productive.
basically i’ve got a website i’m trying to build. i use a few libraries: flip-move, react-virtualized, react-dnd. it’s just excruciating to try to figure out how to use them in cljs. what i hate most of all is that i cannot figure out what’s going on. like yesterday trying to figure out why flip-move won’t load. there’s just nothing for me to do. i tried like 50 combinations of random shit in my config files and different versions of libraries
in JS if i have a problem i can methodically work through it. but in cljs i just get stuck. there’s nothing more i know to try
i reported the flipmove issue, but also several of my react-dnd libraries weren’t loading. i got an error message in teh console, but i have no idea what to do about it
i opened up a new portion of my website that i’m trying to port and saw all of the crazy s* i have built with react-vritualized and i realized it was going to be super hard
the thing is that the primary thing i want from cljs is state management. atoms + specter is freaking amazing
but this only generates the CJS output. it is then treated like any other JS file by JS tool, ie. webpack
interesting. question: is there a “verbose” mode in shadow-cljs to explain what it is doing when it tries to load a library?
because that would have helped me when i was trying to figure out what was going on
I think you got burned hard by the :foreign-libs
mess and NOTHING from that applies to shadow-cljs
okay well let me just try to see if i can get these packages to load before i give up
i think the hard part is that in JS you just cut-n-paste whatever magical BS is required to get things to load. you need to understand that stuff and translate it in cljs
however you got bitten by the problem I described where react-flip-move pretends to be ES when it isn't
what you can always do is (:require ["thing" :as x])
and then (js/console.log "x" x)
if that is just an object with a .default
property you are better off using :default
due to old compat issues there may also be a .default$
property but that is just :default
again
https://code.thheller.com/blog/shadow-cljs/2017/11/10/js-dependencies-in-practice.html
i guess the other thing i was puzzling through is the fact that reagent used to require cljsjs versions of react. so i excluded those. but I just could be sure what I was doing was working. that’s kind of why i was wishing for some kind of diagnostic.
the shim file basically maps the pseudo-ns that :foreign-libs
otherwise would create back to the original npm package
wow you know why I couldn’t get react-flip to work? I was putting “.js” at the end of my :js-options
:require
.
wait no that’s not it. args this is so annoying. i tried all of this last night and it didnt work
i mean i saw that flip move had different distros and i tried resolving it to the .es module even before i reported that issue
:js-options
{:resolve
{"react-flip-move" {:target :npm :require "react-flip-move/dist/react-flip-move.es"}}}
so back on my larger project. what does this mean and how i diagnose it:
shadow-cljs - failed to load module$node_modules$react_dnd$lib$DragDropContextProvider
shadow.js.jsRequire @ shadow.js.js:53
shadow$provide.module$node_modules$react_dnd$lib$index @ index.js:17
shadow.js.jsRequire @ shadow.js.js:51
shadow.js.require @ shadow.js.js:77
(anonymous) @ seekeasy.sidebar.js:10
module$node_modules$react_dnd$lib$DragDropContextProvider
is the internal namespace that is generated for the file
Is the build target exposed anywhere? I have code which works in both node & browser with only a slight change.
@thheller any time I guess build config or runtime, just need to be able to switch my code on it.
(dostuff
(if (goog.node-js)
(js/require "some-canvas-alt")
(js/getElementById "canvas")))
I can do a goog.define 🙂ugh you are getting into tricky territory with conditional requires but yes that would be a candidate for goog-define
it literally just rethrows the error https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/js.js#L53-L54
I just tested (:require ["react-dnd"])
and it works just fine. what exactly do you require?
@thheller Hmm, yes, I hadn't considered that conditional requires might be tricky territory. I don't want to compile into a single js particularly, I want to write a standalone js module (I think, haven't explored this far). Is there anything specific you'd recommend?
:closure-defines
is static at compile time. if you prefer to detect at runtime instead you could use js/process.browser
@lee.justin.m react-dnd
seems painfully hard to use even from the JS side. I would probably never be able to use this without looking at the docs every time.
okay. now i’m losing my mind. i have removed react-flip-move from packages.json. my dependencies look like:
:dependencies
[[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.9.946"]
[reagent "0.8.0-alpha2" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/creat-react-class cljsjs/react-dom-server]]
[hiccup "1.0.5"]
[secretary "1.2.3"]
[cljs-http "0.1.44"]
[com.rpl/specter "1.1.0"]
[venantius/accountant "0.2.3" :exclusions [org.clojure/tools.reader]]
[binaryage/oops "0.5.8"]
[org.clojure/test.check "0.9.0"]]
and now i’m getting The required JS dependency "react-flip-move" is not available, it was required by "cljsjs/react_flip_move.cljs"
Where is that cljsjs coming from?I should probably show the full graph in that exception, eg. everyone involved in that require
okay got all of my stupidity out of the way. now i have a create-react-class issues:
shadow.js.js:53 shadow-cljs - failed to load module$node_modules$create_react_class$index
shadow.js.jsRequire @ shadow.js.js:53
shadow.js.require @ shadow.js.js:77
(anonymous) @ reagent.impl.component.js:3
shadow.js.js:54 Uncaught TypeError: m.Component is not a constructor
at Object.shadow$provide.module$node_modules$create_react_class$index (index.js:23)
at Object.shadow.js.jsRequire (shadow.js.js:51)
at Object.shadow.js.require (shadow.js.js:77)
at reagent.impl.component.js:3
i’m trying to get back to a hello-world and now i’ve obviously messed the buid configuration up so bad it won’t work
this doesn’t work anymore because of all the load errors:
(defn thing [] [:div "goodbye world"])
(defn mount-root []
(reagent/render [thing]
(.getElementById js/document "app")))
there might be a caching error somewhere if you modified the node_modules
directly while the compile is running
nothing is working. somehow i’ve messed up react and reagent. i downgraded to reagent 0.7.0 and i’ve installed the cljsjs/react.js shim
just tried that. same thing. so I should install react, react-dom, and create-react-app via npm, righT?
omg. i deleted node_modules, killed yarn.lock. only those three dependencies (react 15). i have reagent 0.7.0 with no exclusions. killed target. that got me back to a working state
I mean the actual server process? didn't leave anything running in the background or so?
yea i haven’t been backgrounding the server because this smelled like caching. the one thing i haven’t been doing is killing the target. killing the target and resetting node_modules fixed whatever chaos i had created
npm
can install nested versions. so it maybe installed node_modules/thing/node_modules/react
i really don’t think that was it because i’m pretty sure i was looking at the create-react-class files
I have no idea whats doing it, but every refresh seems to clear the console, which is actually a bit convenient
Yeah, either way, I think I like it, so if I find it and fix it, I would have to reimplement it
Yeah, but should be trivial in the reload fn too. What would be even better is if the console can be scrolled to the bottom
I wanted to see if I can compile a modern JS application with shadow-cljs. Turns out I can with no modifications to the source whatsoever. Only config stuff and a manual babel pass due to JSX.
I'll probably write a blog post about this. I guess I can claim that shadow-cljs has pretty good JS support when it can do this. 😉
i’m working through some unexpected things, but i really think most of my problems were related to a stale build
the only weird thing that is happening is that when i’m off of the main entry point, reloading breaks now, presumably because i’m using html5 history
right of course. when i’m not on the root path and i change the code, everything goes haywire and i have to reload