David Kimura PRO said almost 4 years ago on Polling with StimulusJS :
  It has to do with webpacker having the RailsUJS installed. So we import it into our stimilus controller at the top. Otherwise the Rails command within the stimulus controller would not be defined. If you had it defined in the window or extended in Webpacker, then you might not have to import it, but I don't like doing that much as it creates too much cross dependencies (changing a file in one location would affect the functionality of another location).