shadow-cljs icon indicating copy to clipboard operation
shadow-cljs copied to clipboard

Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

Open vnctaing opened this issue 5 years ago • 7 comments

Hi,

I'm trying to use the latest @aws-amplify/ui-react instead of the legacy aws-amplify-react

It's somewhat similar to this stackoverflow issue that is using the legacy import { withAuthenticator } from 'aws-amplify-react';. I was able to make things work with the legacy aws-amplify-react library.

(ns myapp.core
  (:require
   ["@aws-amplify/ui-react" :refer (AmplifyAuthenticator, AmplifySignUp, AmplifySignOut)]
   ["aws-amplify" :default Amplify :as amp]
   ["/aws-exports.js" :default aws-exports]
  (:import goog.History))


(def authenticator (r/adapt-react-class AmplifyAuthenticator ))

(def signup (r/adapt-react-class AmplifySignUp ))

(def amplify-signout (r/adapt-react-class AmplifySignOut ))

(defn home []
    ......
    [authenticator
     [:div
      [amplify-signout]]
     ]
)

But this outputs

Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

I'm expecting it to render the signout component I tried to change the output build to es6 or es8 but no dice

   :builds
   {:app
    {:target     :browser
     :compiler-options {:output-feature-set :es8}
     :output-dir "target/cljsbuild/public/js"
     :asset-path "/js"
     :modules    {:app {:entries [tartataing.app]}}
     :devtools   {:watch-dir "resources/public"}}

Here's the reproducible repo : https://github.com/vnctaing/tartataing/blob/main/src/cljs/tartataing/core.cljs

vnctaing avatar Dec 30 '20 06:12 vnctaing

Try adding :js-options {:babel-preset-config {:targets {:chrome 50}} or so to your build config.

thheller avatar Dec 30 '20 12:12 thheller

No dice, I've even tried to rm -rf .shadow-cljs and rm -rf target/cljsbuild/public/js

vnctaing avatar Dec 31 '20 07:12 vnctaing

I am getting this error Screen Shot 2021-02-17 at 12 39 11 AM

vgautamm avatar Feb 17 '21 05:02 vgautamm

No dice, I've even tried to rm -rf .shadow-cljs and rm -rf target/cljsbuild/public/js

Did you manage to resolve this issue

vgautamm avatar Feb 17 '21 05:02 vgautamm

The amplify libraries nowadays make heavy use of webpack specific features that shadow-cljs does not support. You may need to use webpack as described here to get those working.

thheller avatar Feb 17 '21 09:02 thheller

I'm seeing the same exact issue and it has come up on the #reagent channel on Clojurians slack. I don't know enough (yet) to know how to use webpack to make this work. If anyone comes up with a cookbook solution, please let us know.

rberger avatar Feb 22 '21 06:02 rberger

I have described a solution in a blog post linked below, using both shadow-cljs and webpack as suggested by @thheller

https://davidvujic.blogspot.com/2021/08/hey-webpack-hey-clojurescript.html

DavidVujic avatar Aug 29 '21 18:08 DavidVujic