Fork me on GitHub
#shadow-cljs
<
2018-07-17
>
denis_krivosheev06:07:56

Hi @thheller I’m trying to use posh library in my project. It produces error when load because it calls clojure.walk/postwalk function. In according to ClojureScript documentation https://www.clojurescript.org/about/differences clojure.walk namespace is included to ClojureScript. It works fine with lein and figwheel, but looks like there is no such namespace when I compile it in shadow-cljs. Any thoughts how to fix this?

denis_krivosheev06:07:17

Interesting, if I require [clojure.walk :as walk] and then use it inside my code (even like clojure.walk/postwalk), it works. But if I use it without requiring in this particular namespace, and just use clojure.walk/postwalk it fails. In general case I would just require it, but it’s library code, not mine

thheller07:07:42

@viebel the browser key is fully supported and I tested including aws-sdk and it worked fine. what error do you get?

Yehonathan Sharvit07:07:52

maybe in my case it doesn't work due to :lein true?

thheller07:07:54

@denis_krivosheev code must always be required properly to work yes. you might be able to make it work if you include clojure.walk before including the library. shadow-cljs is a bit stricter about requires due to the parallel compilation

thheller07:07:05

@viebel nope, doesn't affect that at all

thheller07:07:48

I'm gonna need the error you are seeing otherwise I can't help

Yehonathan Sharvit07:07:23

I get this error:

Compiling ClojureScript...
Compiling ["public/clojurescript/main.js"] from ["src/cljs/audyx"]...
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: module not found: "fs" from file /mnt/c/Users/USER/prj/audyx-deps/node_modules/aws-sdk/lib/util.js
    at onresolve (/mnt/c/Users/USER/prj/audyx-deps/node_modules/@cljs-oss/module-deps/index.js:181:30)
    at onResolve (/mnt/c/Users/USER/prj/audyx-deps/node_modules/enhanced-resolve/lib/Resolver.js:70:11)
    at innerCallback (/mnt/c/Users/USER/prj/audyx-deps/node_modules/enhanced-resolve/lib/Resolver.js:143:22)
    at callbackWrapper (/mnt/c/Users/USER/prj/audyx-deps/node_modules/enhanced-resolve/lib/createInnerCallback.js:10:21)
    at next (/mnt/c/Users/USER/prj/audyx-deps/node_modules/tapable/lib/Tapable.js:249:35)
    at innerCallback (/mnt/c/Users/USER/prj/audyx-deps/node_modules/enhanced-resolve/lib/Resolver.js:143:22)
    at callbackWrapper (/mnt/c/Users/USER/prj/audyx-deps/node_modules/enhanced-resolve/lib/createInnerCallback.js:10:21)
    at next (/mnt/c/Users/USER/prj/audyx-deps/node_modules/tapable/lib/Tapable.js:249:35)
    at resolver.doResolve.createInnerCallback (/mnt/c/Users/USER/prj/audyx-deps/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:41:24)
    at callbackWrapper (/mnt/c/Users/USER/prj/audyx-deps/node_modules/enhanced-resolve/lib/createInnerCallback.js:10:21)

thheller07:07:35

that doesn't look like a shadow-cljs error. are you using lein-cljsbuild again?

thheller07:07:50

@cljs-oss/module-deps shadow-cljs never ever uses that

denis_krivosheev07:07:51

@thheller requiring it before the library doesn’t work either

denis_krivosheev07:07:42

(ns differ.core
  (:require
   [datascript.core :as datascript]
   [expound.alpha :as expound]
   [orchestra-cljs.spec.test :as st]
   [cljs.spec.alpha :as s]
   [clojure.walk :as walk] ;; <- here
   [re-posh.core :as re-posh])) ;; <- this library using it

thheller07:07:55

@viebel that doesn't matter. you are not currently using shadow-cljs. I don't know what exactly you are doing but the above error is not produced by shadow-cljs

thheller07:07:12

try removing any reference to figwheel or lein-cljsbuild from your project.clj

thheller07:07:19

or whatever else may be in there

thheller07:07:22

and put it into your classpath and add the clojure.walk require

denis_krivosheev07:07:06

oh, great idea!! thanks!

denis_krivosheev07:07:52

what is the order of classpath walking? my code first or library first?

thheller07:07:04

source-paths always take priority

denis_krivosheev07:07:23

cool! Great thanks!

thheller07:07:52

it should really be fixed in the posh library though

denis_krivosheev07:07:43

Yeah, will create a PR to them

denis_krivosheev07:07:20

@thheller one more thing in my console. I’m building project with target :npm-module and use it from javascript as in your example project. When it starts it throws an error: Uncaught ReferenceError: SHADOW_ENV is not defined

denis_krivosheev07:07:56

even if I start it this way: SHADOW_ENV=development shadow-cljs watch app

thheller07:07:18

thats not what that does 😉

denis_krivosheev07:07:52

Yeah, it’s just my gues. But how to fix this?

denis_krivosheev07:07:07

The same error in your example project

thheller07:07:18

hmm really?

thheller07:07:34

it works just fine on my machine

thheller07:07:38

what is your setup/config?

denis_krivosheev07:07:25

{:source-paths
 ["cljs-src" "cljs-test"]

 :nrepl {:port 8450}

 :dependencies
 [[org.clojure/clojurescript "1.10.339"]
  [org.clojure/clojure "1.9.0"]
  [reagent "0.8.1"]
  [datascript "0.16.6"]
  [orchestra "2017.11.12-1"]
  [expound "0.7.1"]
  [re-posh "0.3.0"]]

 :builds
 {:app {:target :npm-module
        :output-dir "dist/cljs"
        :runtime :browser
        :entries [differ.core differ.chat.views]}
  :test {:target :node-test
         :output-to "dist/cljs/test"}}}

denis_krivosheev07:07:04

I’m using it the same way as in example, except I use not node_modules but just a folder inside my project

thheller07:07:05

runtime browser?

thheller07:07:31

ah CRA right

denis_krivosheev07:07:31

Yes, the error is in runtime. Browser chrome

thheller07:07:18

any particular reason you are not using :target :browser instead? do you need anything from CRA?

denis_krivosheev07:07:43

I wanna migrate my project to clojurescript, but it’s big and there is no way I can rewrite it from scratch. It’s TypeScript and I need interop from TypeScript to ClojureScript and vice versa

thheller07:07:50

I think the :runtime :browser might be causing some confusion. I just tested with node which works fine.

thheller07:07:29

gotta get my test setup running again first

thheller07:07:34

haven't used that in a while

thheller07:07:23

hmm nope also runs fine in the browser for me

thheller07:07:52

please check if dist/cljs/cljs_env.js exists and has a var SHADOW_ENV ... line

thheller07:07:16

and please post the full error you get including the stacktrace

thheller07:07:25

maybe its just in a spot I didn't check

Hukka07:07:52

$ lein run -m shadow.cljs.devtools.cli help
Unknown action.
What might I be doing wrong?

denis_krivosheev08:07:17

browser.cljs:39 Uncaught ReferenceError: SHADOW_ENV is not defined
    at Object.shadow$cljs$devtools$client$browser$goog_is_loaded_QMARK_ [as goog_is_loaded_QMARK_] (browser.cljs:39)
    at shadow$cljs$devtools$client$browser$src_is_loaded_QMARK_ (browser.cljs:48)
    at Function.G__24616__1 [as cljs$core$IFn$_invoke$arity$1] (core.cljs:4222)
    at cljs.core.filter.cljs$core$IFn$_invoke$arity$2 (core.cljs:5124)
    at cljs.core.LazySeq.sval (core.cljs:3394)
    at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (core.cljs:3452)
    at Object.cljs$core$seq [as seq] (core.cljs:1210)
    at Function.cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3 (core.cljs:2445)
    at cljs.core.LazySeq.cljs$core$IReduce$_reduce$arity$3 (core.cljs:3458)
    at Function.cljs.core.reduce.cljs$core$IFn$_invoke$arity$3 (core.cljs:2517)

thheller08:07:28

@tomi.hukkalainen_slac not using shadow-cljs help 😉

Hukka08:07:59

Well, if it doesn't work via lein, then the doc misled me 😞

denis_krivosheev08:07:04

@thheller also I’m using shadow-cljs 2.4.20

denis_krivosheev08:07:27

maybe it’s the reason

thheller08:07:32

@tomi.hukkalainen_slac the help command is more or less useless regardless but currently its implremented only on the CLJS side so its just missing

thheller08:07:43

@denis_krivosheev nah found the issue its in the live reloading code

thheller08:07:07

@denis_krivosheev should be fixed in 2.4.21

denis_krivosheev08:07:46

Great! thank you!

denis_krivosheev08:07:38

@thheller tested. Fixed. Great job! shadow-cljs rocks :the_horns:

Hukka10:07:26

@thheller I was wondering if I should make a repository, that builds a ring-jetty backend and shadow/re-frame frontend commit by commit, documenting the commands in the README (as some of the files in the repo are not written by hand)?

Hukka10:07:37

As soon as I get it working myself, of course

Hukka10:07:43

Hm. How do I tell shadow not to use the version of a an npm library packaged under dist, but instead the non-minified src version, for debugging/development?

Hukka11:07:19

Gah. :js-options :resolve seems to do the trick, but the library is actually jsx, which wasn't really visible from the filenames

Hukka11:07:03

Haha, next section in the guide 🙂

niclasnilsson11:07:10

Any hints on what to do when (server/start!) doesn’t return, as in the example at https://shadow-cljs.github.io/docs/UsersGuide.html#embedded. It just hangs with no output.

niclasnilsson11:07:09

Hmm… It does start under a boot repl, but not under a clj (deps.edn) repl… Any ideas to get it started under clj?

thheller16:07:15

what are you calling? it should work exactly the same in all envs

niclasnilsson16:07:10

Just (server/start!)

niclasnilsson17:07:19

Hmm. I had some other things in my deps.edn as well, but when stripping that out and running a deps.edn with just shadow-cljs in, it does this:

% clj
Clojure 1.9.0
user=> (require '[shadow.cljs.devtools.server :as server])
nil
user=> (server/start!)
Jul 17, 2018 7:03:33 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.8.Final
Jul 17, 2018 7:03:33 PM clojure.tools.logging$eval8756$fn__8759 invoke
WARNING: HTTP startup failed
java.lang.IllegalArgumentException: XNIO001001: No XNIO provider found
        at org.xnio.Xnio.doGetInstance(Xnio.java:270)
        at org.xnio.Xnio.getInstance(Xnio.java:187)
        at io.undertow.Undertow.start(Undertow.java:116)
        at shadow.undertow$start.invokeStatic(undertow.clj:194)
        at shadow.undertow$start.invoke(undertow.clj:158)
        at shadow.cljs.devtools.server$start_http$fn__22410.invoke(server.clj:136)
        at shadow.cljs.devtools.server$start_http.invokeStatic(server.clj:135)
        at shadow.cljs.devtools.server$start_http.invoke(server.clj:131)
        at shadow.cljs.devtools.server$start_system.invokeStatic(server.clj:180)
        at shadow.cljs.devtools.server$start_system.invoke(server.clj:154)
        at shadow.cljs.devtools.server$start_BANG_.invokeStatic(server.clj:349)
        at shadow.cljs.devtools.server$start_BANG_.invoke(server.clj:283)
        at shadow.cljs.devtools.server$start_BANG_.invokeStatic(server.clj:286)
        at shadow.cljs.devtools.server$start_BANG_.invoke(server.clj:283)
        at user$eval22617.invokeStatic(NO_SOURCE_FILE:3)
        at user$eval22617.invoke(NO_SOURCE_FILE:3)
        at clojure.lang.Compiler.eval(Compiler.java:7062)
        at clojure.lang.Compiler.eval(Compiler.java:7025)
        at clojure.core$eval.invokeStatic(core.clj:3206)

niclasnilsson17:07:51

(Not hanging anymore though)

niclasnilsson17:07:58

And upgrading tools.deps fixed the XNIO problem

niclasnilsson17:07:59

And now it works with the other stuff I had in deps.edn as well. So basically, an upgrade of tools.deps (and clojure) made it work.

thheller18:07:17

ah right. yeah older versions of tools.deps didn't support :scope "runtime" which the xnio stuff uses.

niclasnilsson11:07:09

Hmm… It does start under a boot repl, but not under a clj (deps.edn) repl… Any ideas to get it started under clj?

thheller19:07:33

@urbanslug the vals issue you ran into earlier was actually a bug in shadow-cljs which should be fixed in 2.4.22

urbanslug19:07:29

@thheller thanks for the update 🙂