Fork me on GitHub
#shadow-cljs
<
2022-02-25
>
hoppy02:02:23

latest shadow, latest spacemacs, attempting to jack in a node repl:

hoppy02:02:57

any ideas?

thheller05:02:48

@hoppy spacemacs trying to initialize the REPL wrong. dunno what it is sending but looks like a regular piggiback init with an invalid argument

Simon11:02:44

Could it be possible to increase compilation speed by using nextjs’ Rust compiler? https://nextjs.org/blog/next-12

😂 1
pez15:02:47

I'm getting compilation errors on inline defs. foo at line X is being replaced if foo is defed elsewhere. Is there a way I can stop that? The project is using shadow-cljs version 2.16.7.

thheller17:02:41

@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?

pez17:02:35

@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. 😃

thheller19:02:22

I don't know what you are doing but def is top level only and shouldn't be used anywhere

pez22:02:22

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.

thheller06:02:17

ah. much easier to understand what you are talking about with an actual code sample

thheller06:02:06

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

pez07:02:10

Yes, I like the warnings, it’s the error that is causing me troubles.

pez07:02:24

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.

thheller19:02:38

if you are trying to explicitely override the value of a def you can use (set! that-def "later")

thheller19:02:36

a def can't be defined first inline either. that is not how the compiler works.

UlisesMAC19:02:20

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: 

UlisesMAC19:02:27

Also using moment(new Date()).toString() raises the same exception.

thheller19:02:02

what is moment though? I mean how was it imported?

UlisesMAC19:02:04

It is

import moment from 'moment';
and in package.json is
"moment": "^2.29.1",
(here's the library URL https://momentjs.com/)

thheller19:02:10

hmm yeah seems fine. no clue whats up with that

UlisesMAC19:02:59

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"

UlisesMAC19:02:01

I can still pass that date from cljs as a parameter to that JSX component, but it was strange.

thheller19:02:24

which shadow-cljs version? maybe try the latest? also has latest closure compiler verison

UlisesMAC19:02:34

I'm using "2.16.12", I'll update it and try again

UlisesMAC19:02:04

The error persists. If I find a solution I'll post it here.

David Vujic13:02:31

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?

David Vujic13:02:43

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.

thheller15:02:14

interesting. that should be easy to reproduce then

David Vujic16:02:12

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.

thheller19:02:36

weird. that is a closure compiler error. dunno what the problem is though

👍 1
UlisesMAC19:02:59
replied to a thread: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:

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"