This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-25
Channels
- # aleph (18)
- # announcements (7)
- # asami (18)
- # babashka (15)
- # babashka-sci-dev (79)
- # beginners (61)
- # calva (4)
- # clj-kondo (23)
- # cljfx (16)
- # cljs-dev (6)
- # clojure (63)
- # clojure-bay-area (3)
- # clojure-europe (33)
- # clojure-nl (1)
- # clojure-survey (4)
- # clojure-uk (5)
- # clojurescript (136)
- # conjure (1)
- # cursive (8)
- # datahike (7)
- # datalevin (1)
- # datomic (30)
- # emacs (10)
- # events (2)
- # figwheel (2)
- # fulcro (20)
- # google-cloud (1)
- # lsp (6)
- # luminus (4)
- # malli (5)
- # music (3)
- # nextjournal (1)
- # off-topic (9)
- # other-languages (3)
- # pathom (16)
- # polylith (34)
- # re-frame (14)
- # reagent (19)
- # releases (6)
- # sci (2)
- # shadow-cljs (33)
@hoppy spacemacs trying to initialize the REPL wrong. dunno what it is sending but looks like a regular piggiback init with an invalid argument
Could it be possible to increase compilation speed by using nextjs’ Rust compiler? https://nextjs.org/blog/next-12
I'm getting compilation errors on inline defs. foo at line X is being replaced
if foo
is def
ed elsewhere. Is there a way I can stop that? The project is using shadow-cljs version 2.16.7.
@pez you stop that by doing that? the warning is there for a reason? I'm assuming here you mean (def foo 1)
and then (def foo 2)
later?
@thheller yes, like that. However, they are both inline, and in different functions. I'd like to have some way to say that I am allowing myself to do it. 😃
I don't know what you are doing but def
is top level only and shouldn't be used anywhere
While developing I am often doings stuff like
(defn hello [x]
(def x x)
(str "Hello " x))
Then after I call (hello "foo")
i can evaluate (str "Hello " x)
to inspect how my function works.you can set :compiler-options {:warnings {:redef-in-file false}}
to disable this particular warning. although I don't recommend doing so since this is a useful warning to warn that you left some debug code which may have unintended side effects for :advanced
or so
I get neither warnings nor errors when I only have one such inline def for a given symbol, btw. It’s when I have more than one for the same symbol that things blow up.
if you are trying to explicitely override the value of a def you can use (set! that-def "later")
Hi all!
I've seen a strange error while trying to use JSX code.
I'm
requiring and using a Card component written in JSX into ClojureScript,
the component itself works well in a ReactJS project.
The problem raises when this JSX component uses the moment
library, using moment()
(without params) just works, but when passing any kind of parameter
(e.g. date or string) to the same function, Shadow-cljs raises an
exception.
I've already tried importing and using moment
from cljs and it works well with & without params, so this problem
is only present when using it in JSX code and importing it to cljs.
Someone have had this problem or know any solution?
Thanks!
Here's the stack trace when calling it as moment("Fri Feb 25 2022 12:40:18 GMT-0600 (Central Standard Time)").toString()
(calling it as moment().toString()
doesn't give any problem)
[:app] Compiling ...
[:app] Build failure:
failed to convert sources
{:tag :shadow.build.closure/convert-error, :sources [[:shadow.build.classpath/resource "components/common/components/Button/Button.js"] [:shadow.build.classpath/resource "components/common/components/Tag/Tag.js"] [:shadow.build.classpath/resource "components/common/components/Card/hooks/useCard.js"] [:shadow.build.classpath/resource "components/common/components/Card/Card.js"]]}
ExceptionInfo: failed to convert sources
shadow.build.closure/convert-sources*/fn--12611 (closure.clj:1540)
shadow.build.closure/convert-sources* (closure.clj:1534)
shadow.build.closure/convert-sources* (closure.clj:1419)
shadow.build.closure/convert-sources (closure.clj:1759)
shadow.build.closure/convert-sources (closure.clj:1691)
shadow.build.compiler/maybe-closure-convert (compiler.clj:1218)
shadow.build.compiler/maybe-closure-convert (compiler.clj:1211)
shadow.build.compiler/compile-all (compiler.clj:1454)
shadow.build.compiler/compile-all (compiler.clj:1330)
shadow.build.api/compile-sources (api.clj:261)
shadow.build.api/compile-sources (api.clj:253)
shadow.build/compile (build.clj:463)
shadow.build/compile (build.clj:453)
shadow.cljs.devtools.server.worker.impl/build-compile (impl.clj:368)
shadow.cljs.devtools.server.worker.impl/build-compile (impl.clj:349)
shadow.cljs.devtools.server.worker.impl/do-resource-update (impl.clj:540)
shadow.cljs.devtools.server.worker.impl/do-resource-update (impl.clj:495)
shadow.cljs.devtools.server.util/server-thread/fn--15941/fn--15942/fn--15950 (util.clj:269)
shadow.cljs.devtools.server.util/server-thread/fn--15941/fn--15942 (util.clj:268)
shadow.cljs.devtools.server.util/server-thread/fn--15941 (util.clj:241)
java.lang.Thread.run (Thread.java:829)
Caused by:
RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.
null
Node(CALL): components/common/components/Card/Card.js:56:6
moment("Fri Feb 25 2022 12:40:18 GMT-0600 (Central Standard Time)").toString()
Parent(GETPROP toString): components/common/components/Card/Card.js:56:74
moment("Fri Feb 25 2022 12:40:18 GMT-0600 (Central Standard Time)").toString()
com.google.javascript.jscomp.Compiler.throwInternalError (Compiler.java:2907)
com.google.javascript.jscomp.NodeTraversal.throwUnexpectedException (NodeTraversal.java:442)
com.google.javascript.jscomp.NodeTraversal.traverse (NodeTraversal.java:462)
com.google.javascript.jscomp.NodeTraversal.access$200 (NodeTraversal.java:38)
com.google.javascript.jscomp.NodeTraversal$Builder.traverse (NodeTraversal.java:398)
com.google.javascript.jscomp.NodeTraversal.traverse (NodeTraversal.java:468)
com.google.javascript.jscomp.ConstParamCheck.process (ConstParamCheck.java:63)
com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process (PhaseOptimizer.java:317)
com.google.javascript.jscomp.PhaseOptimizer.process (PhaseOptimizer.java:232)
com.google.javascript.jscomp.Compiler.performTranspilationAndOptimizations (Compiler.java:2592)
com.google.javascript.jscomp.Compiler.lambda$stage2Passes$8 (Compiler.java:966)
com.google.javascript.jscomp.CompilerExecutor.runInCompilerThread (CompilerExecutor.java:127)
com.google.javascript.jscomp.Compiler.runInCompilerThread (Compiler.java:1014)
com.google.javascript.jscomp.Compiler.stage2Passes (Compiler.java:963)
com.google.javascript.jscomp.Compiler.compile (Compiler.java:846)
jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke (Method.java:566)
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:167)
clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:102)
shadow.build.closure/convert-sources*/fn--12611/fn--12612 (closure.clj:1538)
shadow.build.closure/convert-sources*/fn--12611 (closure.clj:1535)
shadow.build.closure/convert-sources* (closure.clj:1534)
shadow.build.closure/convert-sources* (closure.clj:1419)
shadow.build.closure/convert-sources (closure.clj:1759)
shadow.build.closure/convert-sources (closure.clj:1691)
shadow.build.compiler/maybe-closure-convert (compiler.clj:1218)
shadow.build.compiler/maybe-closure-convert (compiler.clj:1211)
shadow.build.compiler/compile-all (compiler.clj:1454)
shadow.build.compiler/compile-all (compiler.clj:1330)
shadow.build.api/compile-sources (api.clj:261)
shadow.build.api/compile-sources (api.clj:253)
shadow.build/compile (build.clj:463)
shadow.build/compile (build.clj:453)
shadow.cljs.devtools.server.worker.impl/build-compile (impl.clj:368)
shadow.cljs.devtools.server.worker.impl/build-compile (impl.clj:349)
shadow.cljs.devtools.server.worker.impl/do-resource-update (impl.clj:540)
shadow.cljs.devtools.server.worker.impl/do-resource-update (impl.clj:495)
shadow.cljs.devtools.server.util/server-thread/fn--15941/fn--15942/fn--15950 (util.clj:269)
shadow.cljs.devtools.server.util/server-thread/fn--15941/fn--15942 (util.clj:268)
shadow.cljs.devtools.server.util/server-thread/fn--15941 (util.clj:241)
java.lang.Thread.run (Thread.java:829)
Caused by:
NullPointerException:
It is
import moment from 'moment';
and in package.json is
"moment": "^2.29.1",
(here's the library URL https://momentjs.com/)If I use it in cljs as:
["moment" :as moment]
when using the REPL, it just works:
(.toString (moment "Fri Feb 25 2022 12:40:18 GMT-0600 (Central Standard Time)"))
=> "Fri Feb 25 2022 12:40:18 GMT-0600"
I can still pass that date from cljs as a parameter to that JSX component, but it was strange.
which shadow-cljs version? maybe try the latest? also has latest closure compiler verison
I have an idea about what may cause it: just experimented with importing a JavaScript file, that imports the moment library, and could reproduce it when using “modern js” syntax. When using the CommonJS syntax all went as expected. Could it be that the jsx component need to go through a Babel parser before requiring it to your clojurescript namespace?
So, this will work:
const moment = require("moment");
function getFriday() {
const d = "Fri Feb 25 2022 12:40:18 GMT-0600 (Central Standard Time)";
return moment(d);
}
module.exports = {
getFriday,
};
By replacing the import to
import moment from "moment";
will output the error.I think that moment might be the reason. Could it be some CommonJS vs ES support thing in the package? :thinking_face:
Tried out date-fns, using the ES syntax
import { formatISO } from "date-fns"
and also exporting the function using
export default myFunction
and that works fine when importing into ClojureScript.