This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-14
Channels
- # announcements (1)
- # asami (3)
- # aws (1)
- # babashka (22)
- # beginners (39)
- # calva (21)
- # clj-kondo (10)
- # cljdoc (22)
- # cljs-dev (17)
- # clojure (93)
- # clojure-australia (3)
- # clojure-europe (39)
- # clojure-italy (3)
- # clojure-losangeles (17)
- # clojure-nl (14)
- # clojure-russia (2)
- # clojure-uk (5)
- # clojurescript (35)
- # community-development (7)
- # conjure (2)
- # cursive (13)
- # data-science (1)
- # datomic (25)
- # emacs (5)
- # events (4)
- # figwheel-main (2)
- # fulcro (12)
- # graphql (7)
- # gratitude (2)
- # inf-clojure (6)
- # leiningen (6)
- # lsp (49)
- # malli (13)
- # membrane (30)
- # minecraft (1)
- # pathom (3)
- # pedestal (26)
- # polylith (13)
- # portal (2)
- # quil (3)
- # random (1)
- # re-frame (13)
- # reagent (43)
- # reitit (6)
- # releases (1)
- # reveal (2)
- # ring (3)
- # shadow-cljs (30)
- # specter (5)
- # sql (8)
- # tools-build (1)
- # tools-deps (13)
- # videos (1)
I’m using react-bootstrap and Reagent. Versions: • reagent 1.1.0 • react 17.0.2 • react-dom 17.0.2 • Trying to upgrade from react-bootstrap 1.6.3 to 2.0.0-rc.0 With react-bootstrap 1.6.3 all is OK. With 2.0.0-rc.0 I get the following error:
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
My code (which I put together last year with lots of help from Google, and which I don’t fully understand) is:
(ns my-ns (:require ["react-bootstrap/Col" :as rb-Col]))
(def ^:private component
(memoize
(fn [obj k & ks]
(if (seq ks)
(apply goog.object/getValueByKeys obj k ks)
(goog.object/get obj k)))))
(defn ^:private reagent-ify [obj & ks]
(fn [& args]
(if ks
(vec (concat [:> (apply component obj ks)] args))
(vec (concat [:> obj] args)))))
(def b-Col rb-Col)
(def Col (reagent-ify b-Col))
Example use:
[Col {:class "col-3"} "Hello]
Any ideas what’s wrong?You seem to be trying to replicate something that Reagent already provides. Not sure what resources you found on Google, but just reading Reagent examples and documentation would've been a much better bet.
Remove everything except for the NS declaration, add something like [reagent.core :as r]
to the :require
. And just add (def Col (r/adapt-react-class rb-Coll))
. That should do it.
Thanks — that will simplify things! I’ve made those changes and I have the same problem — all good with react-bootstrap 1.6.3 but that same error with 2.0.0-rc.0. I’ll create a minimal example and see if I discover anything as a result.
It's probable that the API has simply changed between the versions and your current usage of it is simply incorrect and has nothing to do with CLJS at all.
I now have a situation where I can’t even require “react-bootstrap/Col”. I’m getting NullPointerException: NAME $jscomp 66:8 [length: 96] [source_file: node_modules/react-bootstrap/cjs/Col.js]
I don’t know what’s changed.
I’ve looked in my node-modules at the Col directory and that looks just the same as the directories for other components.
I’m going to take a break and continue later.
No clue but purging all caches, updating your build tools, and removing node_modules
and installing the NPM packages again IMO is worth trying.
If that doesn't work, create a minimal reproducible example - I'll take a look.
@U2FRKM4TW Thanks! I’ve created a minimal repro at https://github.com/simon-katz/react-bootstrap-col-problem It’s a shadow-cljs project. The README has instructions on how to reproduce the issue.
I’ve purged all the caches I know about, removed node-modules
and reinstalled NPM packages, and I think I have all build tools up to date,
Add :js-options {:entry-keys ["module" "browser" "main"]}
to the :compiler-options
section. More details: https://shadow-cljs.github.io/docs/UsersGuide.html#js-entry-keys
Minor correction: I had to add the :js-options
at the same level as the :compiler-options
.
Thanks, that does indeed fix the problem demonstrated in my minimal reproduction. Now, in my actual project, I’m back to the “type is invalid” errors. I’ll take another look tomorrow.
BTW, the purpose of my reagent-ify
is to allow things like:
(def Accordion (reagent-ify b-Accordion))
(def Accordion_Body (reagent-ify b-Accordion "Body"))
(def Accordion_Header (reagent-ify b-Accordion "Header"))
(def Accordion_Item (reagent-ify b-Accordion "Item"))
r/adapt-react-class
only takes a single argument.
Why not (def Accordion_Body (r/adapt-react-class (.-Body b-Accordion)))
? All you do is just getting the field in component
, that's it - you can do it outside of adapt-react-class
.
please note that setting :entry-keys
here is not actually the "fix". it just seems to avoid a bug in the closure compiler you otherwise run into. I can reproduce it but it happens deeply in closure compiler code and I don't see a way to fix it from shadow-cljs.
@U05224H0W Thanks for your input. When you say “it happens deeply in closure compiler code”, are you referring to the error when requiring “react-bootstrap/Col” (which doesn’t happen if I have the require in my code when first compiling — only if I add the require in and have “shadow-cljs watch” load the changed code)?
Or are you referring to the “React.createElement: type is invalid -- expected a string” errors I mentioned (which I get if the require is in place for the initial compile, and when I try to use Col
?
Just wondering if I have to give up on trying to upgrade from react-bootstrap 1.6.3 to 2.0.0-rc.0.
The React.createElement
error is likely unrelated and is due to how you end up using Col
exactly.
If you add such a usage example to that same repo, I can take a look.
Or, assuming it's not too much code, you can just paste it here - it's likely that the problem is obvious.
Thanks. My repo now has a new branch named “further-investigation”.
In the “ui” namespace, there’s a var called demo-col-error?
If false
, the UI displays with no error. If true
, I get the “type is invalid” error.
Notes:
I’ve changed the HTTP port to 8281 (so that I can run this and my real app at the same time.
The value of rb-Col
is different in kind to the values of rb-Row
and rb-Container
. See lines 12-14 of ui.cljs
.
I was referring to this error
Caused by:
NullPointerException: NAME $jscomp 66:8 [length: 96] [source_file: node_modules/react-bootstrap/cjs/Col.js]
com.google.common.base.Preconditions.checkNotNull (Preconditions.java:897)
com.google.javascript.jscomp.RemoveUnusedCode.getVarForNameNode (RemoveUnusedCode.java:891)
com.google.javascript.jscomp.RemoveUnusedCode.traverseNameNode (RemoveUnusedCode.java:746)
com.google.javascript.jscomp.RemoveUnusedCode.traverseNode (RemoveUnusedCode.java:571)
com.google.javascript.jscomp.RemoveUnusedCode.traverseNormalOrOptChainGetProp (RemoveUnusedCode.java:629)
com.google.javascript.jscomp.RemoveUnusedCode.traverseNode (RemoveUnusedCode.java:577)
com.google.javascript.jscomp.RemoveUnusedCode.traverseChildren (RemoveUnusedCode.java:1301)
com.google.javascript.jscomp.RemoveUnusedCode.traverseCall (RemoveUnusedCode.java:803)
com.google.javascript.jscomp.RemoveUnusedCode.traverseNode (RemoveUnusedCode.java:498)
com.google.javascript.jscomp.RemoveUnusedCode.traverseDeclarationStatement (RemoveUnusedCode.java:1082)
com.google.javascript.jscomp.RemoveUnusedCode.traverseNode (RemoveUnusedCode.java:550)
com.google.javascript.jscomp.RemoveUnusedCode.traverseChildren (RemoveUnusedCode.java:1301)
com.google.javascript.jscomp.RemoveUnusedCode.traverseFunction (RemoveUnusedCode.java:1442)
com.google.javascript.jscomp.RemoveUnusedCode.traverseNode (RemoveUnusedCode.java:467)
com.google.javascript.jscomp.RemoveUnusedCode.traverseChildren (RemoveUnusedCode.java:1301)
com.google.javascript.jscomp.RemoveUnusedCode.traverseCall (RemoveUnusedCode.java:803)
React.createElement: type is invalid -- expected a string
could just be that the react-bootstrap
package changed how they export the code
Even with the right imports (had to use :default
instead of :as
when the :js-options
workaround was used), it still results in an error: Col.js:68 Uncaught TypeError: $jscomp.makeIterator is not a function
And using :output-feature-set :es5
fixes it, so I guess @U06A9U5RP if you want to use the newer version of react-bootstrap
, you're stuck with ES5 for now, unless there's some other workaround.
Isn't it the same with :js-options
, given how it's just a workaround for a bug in GCC?
$jscomp.makeIterator is not a function
this means that a polyfill is missing. so the code was rewritten but somehow the polyfill was not accounted for properly
@U2FRKM4TW @U05224H0W Thank you both for your help.
@U05224H0W Will you be creating an issue for this? If so, please will you post a link so that I can follow it?
$jscomp
is just the object created for polyfills, so yeah it does many things and each error likely means something different
the first issue also might actually be coming from shadow-cljs. it compiles fine when the file is required in the initial compile. it only fails on incremental compile