Fork me on GitHub

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
   (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.


How do you use Col?


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 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:


Minor correction: I had to add the :js-options at the same level as the :compiler-options.

👍 1

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.


Thanks. Yes, that’s much better.

👍 1

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.

👍 2

also seems to be polyfill related which makes it extra hard to track down


@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] ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (


React.createElement: type is invalid -- expected a string could just be that the react-bootstrap package changed how they export the code


so using :as may no longer be correct when they switch to using default exports


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.


please do not ever give this advice


if setting :es5 happens to fix something that is a bug


it should be reported and I will look into it


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


that is likely a bug in shadow-cljs


Ah, so then not all $jscomp errors are equal, alright.


@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

👍 1

feel free to create an issue yourself


Sure. Sorry —I misunderstood you.


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

👍 1

so the cache might not be providing something properly it is supposed to provide or the GCC just doesn't like that I'm incrementally compiling something that was polyfilled. something it itself doesn't do.