Fork me on GitHub
#shadow-cljs
<
2018-09-24
>
Jakub Holý09:09:54

Can anybody shed a light why shadow-cljs release hides js/React from my code? I use shdow-cljs to produce an npm-module, which is then consumed by a .js file, processed by Webpack (during a gatsby build run). When I shadow-cljs compile app then everything works just fine. However, when I do shadow-cljs release app instead then webpack fails with > WebpackError: js/React is missing (thrown from https://github.com/reagent-project/reagent/blob/v0.7.0/src/reagent/impl/util.cljs#L12) Why? What can I do to fix it? (The .js file that requires my cljs-based npm module does import React) Thansk a lot!!!! (Here is the code: https://github.com/jakubholynet?tab=repositories)

thheller09:09:43

@holyjak shadow-cljs doesn't hide anything from you. the pattern reagent uses is just not compatible with node

thheller09:09:51

you should upgrade to the latest reagent version

Jakub Holý09:09:42

I did not mean to defame shadow-cljs 🙂 Thanks a lot, awesome that you know what the problem is. However I cannot upgrade easily as I have to use React 15 and Reagent 0.8 requires 16. Do you think that somebody in #reagent could help? Or is there anything else I can do? I guess what Reagent does somehow fails under :advanced for some reason?

thheller09:09:06

0.8.1 I believe

4
thheller09:09:36

you can try to call (set! js/global.React react) with (:require ["react" :as react])

thheller09:09:05

why does reagent require v16? I don't think thats true

thheller09:09:31

note that the cljsjs version it depends on it completely irrelevant as that won't be used

thheller09:09:44

it will use the react version you installed via npm in your project

thheller09:09:53

so if you install v15 you should be good to go?

Jakub Holý09:09:41

I don't know, I saw that reagent v8 updated to React 16 and I have assumed it is not backwards compatible with 16 but I haven't really tried. I will try to upgrade then. I have v15 installed (and it worked in dev, non-release). I will also try the call you suggested. Thanks a lot, you are extremely helpful!

thheller09:09:24

try upgrading first. I don't think reagent adopted any of the newer lifecycle methods yet so it shouldn't matter

thheller09:09:58

it works in dev because the development loader works differently there

👍 4
thheller10:09:06

@holyjak I think you are making things a bit more complicated than they need to be

thheller11:09:17

damn gatsby is one gigantic mess

thheller11:09:24

seriously wtf ...

Jakub Holý12:09:34

Thanks a lot, upgrade to Reagent 0.8 solved the problem and it now works with release just nicely

thheller12:09:49

@holyjak I got curious about the gatsby stuff an implemented a minimal example of how I would approach this

thheller12:09:24

(defn page-index
  {:export true
   :gatsby/page "index"
   :gatsby/graphql
   "query IndexQuery {
      site {
        siteMetadata {
          description
        }
      }
   }"}
  [props]
  (r/as-element
    [:h1 "hello world!"]))

thheller12:09:34

basically the idea is that you create a normal clojure function for each page

thheller12:09:40

add some metadata to it that a build hook will then extract and create the src/pages files

thheller12:09:44

it bypasses all the other gatsby stuff basically. you just write a function per page

thheller12:09:13

not a clue how the dynamic createPages stuff would work but should be simple to hook up AFAICT

thheller12:09:45

granted that I would not expect anyone to know how to write the hook but its pretty simple https://github.com/thheller/gatsby-cljs/blob/master/src/main/shadow/gatsby.clj

thheller12:09:55

could be made easier with macros properly but I didn't use any since metadata is probably enough

❤️ 4
Jakub Holý08:09:28

Man , you rock! I have been working on this in the past three days and you came in a short time with a better and much nicer solution! Thank you!

ClashTheBunny13:09:40

Hey there! I'm wondering how to fix an update to shadow-cljs. I updated it and now I get The required namespace is not available.

ClashTheBunny13:09:06

The full error is

[email protected] ~/code/deck-builder (master●●●)$ cd ~/code/deck-builder; rlwrap npx shadow-cljs clj-repl
shadow-cljs - config: /Users/ranmason/code/deck-builder/shadow-cljs.edn  cli version: 2.6.9  node: v10.10.0
shadow-cljs - starting via "clojure"
Sep 24, 2018 8:10:10 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.8.Final
Sep 24, 2018 8:10:10 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.8.Final
shadow-cljs - HTTP server for :browser available at 
shadow-cljs - HTTP server for :browser-test available at 
shadow-cljs - HTTP server for :devcards available at 
shadow-cljs - server version: 2.6.9
shadow-cljs - server running at 
shadow-cljs - socket REPL running on port 50235
shadow-cljs - nREPL server started on port 8230
shadow-cljs - REPL - see (help)
To quit, type: :repl/quit
[1:0]~shadow.user=> (shadow/once :devcards)
[:devcards] Compiling ...
The required namespace "devcards.core_card" is not available.

:error
[1:0]~shadow.user=> (shadow/once :devcards)
[:devcards] Compiling ...
The required namespace "devcards.core_card" is not available.

:error
[1:0]~shadow.user=>

ClashTheBunny13:09:28

I went from 2.5.1 to 2.6.9.

ClashTheBunny13:09:28

I may have upgraded from 2.0.144, but I don't have the logs from when it worked last.

thheller14:09:17

@clashthebunny did you update devcards in the meantime too? or mess with your source-paths in any way?

thheller14:09:06

devcards.core_card isn't part of devcards itself? is that one of your sources?

thheller14:09:44

you can run shadow-cljs clj-repl (shadow/find-resources-using-ns 'devcards.core_card) to figure out who is using that

ClashTheBunny14:09:06

I did update it at the same time!

ClashTheBunny14:09:17

I'll keep digging. Thanks for the pointers.

Nolan14:09:29

hey everyone, saw https://clojureverse.org/t/shadow-cljs-and-leinigen-and-npm-oh-my/2735/22 and have been able to connect vim-fireplace to the nREPL started by shadow-cljs watch service I ran :Piggieback :service as well with no confirmation if that worked properly. When I try to evaluate a form that uses reader conditionals (just :clj and :cljs) in a .cljc, I get “Conditional read not allowed”. Is this because :Piggieback is failing, or some other configuration issue?

thheller16:09:51

@nolan its not shadow-cljs since I can use them just fine in the REPL directly

[2:1]~cljs.user=> #?(:cljs 1)
1

thheller16:09:57

seems to work fine over nrepl as well so its probably vim-fireplace?

thheller16:09:09

looking at the full exception should tell you

Nolan16:09:31

right on. i am able to do the same in the repl directly. not a huge issue. I’ll check into it a bit more later. thanks!

lilactown19:09:10

about every other time I run my builds, I see this error message:

failed to require :target :browser-test for build :browser-tests
CompilerException: java.lang.RuntimeException: Unable to resolve symbol: defelem in this context, compiling:(hiccup/page.clj:20:1)
	clojure.lang.Compiler.analyze (Compiler.java:6792)
	clojure.lang.Compiler.analyze (Compiler.java:6729)
	clojure.lang.Compiler$InvokeExpr.parse (Compiler.java:3813)
	clojure.lang.Compiler.analyzeSeq (Compiler.java:7005)

lilactown19:09:24

RuntimeException: Unable to resolve symbol: defelem in this context
	clojure.lang.Util.runtimeException (Util.java:221)
	clojure.lang.Compiler.resolveIn (Compiler.java:7299)
	clojure.lang.Compiler.resolve (Compiler.java:7243)

thheller19:09:34

hmm this was supposed to be fixed a while ago. which version are you on?

lilactown19:09:51

2.6.8. it started happening after upgrade to that version from 2.4.x