What does this do: `const { $ } = require("@rails/ujs");` within my Rails app? It seems to be causing an error

108 Views Asked by At

in app/javascript/packs/application.js I see: const { $ } = require("@rails/ujs");

For some unknown reason, I get this error:

rails-ujs.js:73 Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '[object HTMLDocument]' is not a valid selector.
    at ./node_modules/@rails/ujs/lib/assets/compiled/rails-ujs.js.Rails.$ (http://192.168.1.34:3000/packs/js/application-82ae508a0043ae1b2583.js:1497:52)
    at Object../app/javascript/packs/application.js (http://192.168.1.34:3000/packs/js/application-82ae508a0043ae1b2583.js:207:1)
    at __webpack_require__ (http://192.168.1.34:3000/packs/js/application-82ae508a0043ae1b2583.js:20:30)
    at http://192.168.1.34:3000/packs/js/application-82ae508a0043ae1b2583.js:84:18
    at http://192.168.1.34:3000/packs/js/application-82ae508a0043ae1b2583.js:87:10

When I comment out the line: const { $ } = require("@rails/ujs"); - then the error goes away, but I don't know if I need this line or not?

This error wasn't happening before... wish I had more details, but I don't.

0

There are 0 best solutions below