This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-28
Channels
- # announcements (33)
- # aws (2)
- # babashka (14)
- # beginners (128)
- # calva (34)
- # cestmeetup (3)
- # clj-kondo (12)
- # cljdoc (3)
- # clojure (114)
- # clojure-europe (31)
- # clojure-italy (3)
- # clojure-nl (7)
- # clojure-uk (6)
- # clojurescript (35)
- # conjure (20)
- # cursive (3)
- # data-science (3)
- # datomic (16)
- # docker (13)
- # events (1)
- # figwheel-main (22)
- # fulcro (109)
- # jobs (1)
- # kaocha (8)
- # keechma (1)
- # lambdaisland (5)
- # malli (1)
- # meander (8)
- # mid-cities-meetup (1)
- # off-topic (6)
- # overtone (7)
- # pathom (6)
- # re-frame (2)
- # reitit (9)
- # ring (1)
- # shadow-cljs (92)
- # specter (1)
- # tools-deps (311)
- # xtdb (76)
I'm kinda stumped on an issue. I need to use requirejs on this platform (no getting around it unfortunately), and shadow appears to be having conflicts. Specifically, loading modules with the usual ["namespace" :as something]
appears to replace whatever requirejs is loading
Any hints/things to look into would be appreciated
Turns out it was just the library I was bringing in (nprogress) which seems to load itself globally for some reason. I don't need it. Other libraries are loading fine
I am trying to use js code within a shadow-cljs project.
shadow-cljs.edn
:
{:source-paths
["src/cljs"
"src/js"]
...
From src/cljs/.../core.cljs
, I want to render a react component exported from a js file
(ns core
(:require ["react" :as react]
["react-dom" :as react-dom]
["/Component.js" :default Example]))
(.log js/console Example)
(defn init! []
(react-dom/render (Example) (js/document.querySelector "#root")))
(defn reload! []
(init!))
src/js/Component.js
:
import React from "react";
export default function Example() {
return React.createElement(
"div",
...
first of all forget about src/cljs
and src/js
. just put the .js
file in the same directory as your CLJS file
Ok, i babel them now to the cljs folder, the issue is
TypeError: Cannot read property 'createElement' of undefined
React
is not loaded properly somehow.
voila, it works.
Thanks.
Yes, I have seen that you translate it to commonJS imports.
But have no idea how those really work.
its sort of undefined since regular ESM (eg. actual browsers) do not support it at all
oh, ok. didnt know that
some tools like webpack or babel just tried to hide it and now we have to deal with the consequences of everything being shit for a while 😛
Thanks. :hugging_face:
pretty print true and what's the other one for figuring out what's up with advanced optimizations fuzzing up?
aha, pseudo-names... or --debug... wish me luck
first step should be turning on externs inference in case it isn't https://shadow-cljs.github.io/docs/UsersGuide.html#infer-externs
check. got that. ... well here look
i'm getting this from a text input
will do more investigating...
About the new :target :esm.. Shouldn't it include the shadow.cljs.devtools.client.env.js
in the dev compiled outputted esm module? As it uses shadow.cljs.devtools.client.env.module_loaded
. I'm always getting the error
Uncaught TypeError: Cannot read property 'module_loaded' of undefined
at shared.js:91
It doesn't get included in my shared.js
file. It's fixed when I include the lines
import "./cljs-runtime/shadow.cljs.devtools.client.env.js";
SHADOW_ENV.setLoaded("shadow.cljs.devtools.client.env.js");
uhh, invoking --debug in console but not getting --debug results... will try with flag
Hey Thomas.. as you are here reading my messages :face_with_rolling_eyes: I commented in one of your answers here https://clojureverse.org/t/generating-es-modules-browser-deno/6116/10?u=jponline
@sova could be that the error is deep in some already minified npm package? that wouldn't be affected by --debug
or --pseudo-names
?
@jpsoares106 I don't really understand what you are asking. you want to publish some web components written in CLJS as a npm library to be consumed by JS users?
o.o i suppose, i'm not using a lot of crazy things... i didn't go out of my way to minify anything
(rum/defc user-chat-input < rum/reactive []
#?(:cljs (let [csrf-token (.getAttribute (. js/document (getElementById "aft")) "data-aft")
input-atom (rum/react user-msg-input-atom)]
[:div.userinputwrap
[:div.userinputrapp
[:form#in {:on-submit (fn [e] (.preventDefault e)
(.log js/console "send message via sente net event")
(chsk-send! [:clientsent/chat-msg {:input input-atom :location (js/decodeURI (. (. js/window -location) -pathname))}])
(reset! user-msg-input-atom "")
)}
[:input {:placeholder "submit chat here, be kind"
:auto-focus true
:value (rum/react user-msg-input-atom)
:on-change (fn [e] (do (println (-> e .-target .-value))
(reset! user-msg-input-atom (-> e .-target .-value))))}]]
[:script {:src (str "main.js?v" 6)}]]]))
#?(:clj
[:div.userinputwrap
[:div.userinputrapp
[:form#in
[:input {:placeholder "submit chat here, be kind" :autofocus true}]]
[:script {:src (str "main.js?v" 6)}]]]))
at a glance can you catch anything egregious ?oh i wonder why the --debug build is not showing up q.q
just happens to be where the script is included 😂
yeah, but you're it ought not be loaded until all components are loaded?
saying *
I don't have a clue what you are doing but loading a script like that looks like an error to me
oh, thanks, i was not aware of that
how ought i do that?
just don't include the script again on the clientside
not the case 😄
legitas.
cljs is still a blurry new landscape to me... thank you for your help
and unfailing patience
Hmm... I am using --debug but still getting these minified errors.
I am probably missing something obvious...
and whatever file that is producing you are loading on the page? not some old file sitting in a different dir or so?
let me double check that part
seems like output?
ok that looks like its deep on react-dom
code (which is already minified so its not affected by --debug
)
Ah okay
Not sure what to make of it. Do you spot anything wild in these lines
(let [in-data (cljs.reader/read-string (.getAttribute (. js/document (getElementById "pcp")) "data-mggs"))
in-answers (cljs.reader/read-string (.getAttribute (. js/document (getElementById "pcp")) "data-inanswers"))
page-type (.getAttribute (. js/document (getElementById "pcp")) "page-type")]
(println page-type in-data in-answers)
(reset! indata in-data) ;set storange atoms
(reset! inansw in-answers)
(if (= "question" page-type) (do (rum/hydrate (question-page @indata @inansw) (.getElementById js/document "rhqp"))
(rum/hydrate (user-chat-input) (.getElementById js/document "uci"))))
(if (= "room" page-type) (do (rum/hydrate (chat-page in-data) (.getElementById js/document "rhcp"))
(rum/hydrate (user-chat-input) (.getElementById js/document "uci"))
(scroll-to-bottom)))
(if (= "allqp" page-type) (do (rum/hydrate (all-question-page @indata)
(.getElementById js/document "rhaq")) ))
(if (= "setts" page-type)
(let [in-dn (.getAttribute (. js/document (getElementById "ecce")) "data-displayname")]
(reset! displayname in-dn)
(.log js/console in-dn)
(rum/hydrate (rolo-settings @displayname)
(.getElementById js/document "rhsp"))
;(rum/hydrate (user-chat-input) (.getElementById js/document "uci"))
)))
a snippet from client.cljs that has the rum/hydrate methods
no problem. it's just a way to get the clientside to nimbly saddle onto the pre-rendered server html
it just sucks because the un-optimized version is 2.4MB and it ought be maybe 750k
I know what hydrate is ... I just have never used it so I cannot help you figure out what it needs
it might be trying to look up functions by name or so which doesn't work with :advanced
since they are all renamed
it's 6.9MB when not a release build
hmm so some things are getting renamed...