Adding custom javascript results in "Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "trix-toolbar" has already been used with this registry"
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
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
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.
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
Any advice or help is appreciated.
Georg
Notifications
You’re not receiving notifications from this thread.