We've moved discussions to Discord

Adding custom javascript results in "Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "trix-toolbar" has already been used with this registry"

Georg Törnqvist
Hi!

Summary
Adding a custom javascript using javascript_pack_tag seems to import the script twice.

How to reproduce
Starting from a fresh jumpstart setup, I added a custom javascript test.js containing 
console.log('Hello from My Test JS');
 in the javascript/packs directory (according to method 3 as described here.  https://dev.to/morinoko/adding-custom-javascript-in-rails-6-1ke6.)

Then, I apply the 
<%= javascript_pack_tag 'test' %>
to the relevant view.

Result
Then, in the browser console I see "Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "trix-toolbar" has already been used with this registry" appear.

I also see the log message 'Hello from My Test JS' appear two times. So, it looks like the javascipt file is being executed (imported) two times.

I've searched the web and this forum finding other people having bumped into the same error message, but for, at least seemingly, other reasons.

PS doing 
require("packs/test")
 from the application.js does seem to import the javascript correcty, however, it does so globally, which is not optimal my this case.

Any advice or help is appreciated.
Georg
Darren Smyth
I don't think this has anything to do with custom javascript as I was getting the same error without my own custom javascript. I'm still trying to work out where it might be coming from.
Georg Törnqvist
Thanks for the input Darren! Have you run into any "real" issues related to this? Or can one just ignore the error message for now?
Darren Smyth
It's interesting. I rolled back the update and did it again and that issue seems to have "gone". Now I have a problem where none of the stimulus controllers are working. It makes no sense as they all work before the update.
Georg Törnqvist
After I'd upgraded jumpstart the issue was resolved.
Notifications
You’re not receiving notifications from this thread.