Rails/ujs import

Stimulus controller handles submitting form via rails ujs. The problem is rails ujs module does not load and it fails with Uncaught ReferenceError: Rails is not defined


import { Controller } from "stimulus"
import Rails from "@rails/ujs"

export default class extends Controller {
  static targets = [ "form" ]
  update() {
     Rails.fire(this.formTarget, 'submit')



Any ideas on what could be the issue? I throw away a few hours of research and couldn’t figure out why Rails is not defined. I followed this post https://www.betterstimulus.com/rails-ujs/submit-form.html

Need expose the Rails in JS world, something like below commit.

Thank you.
I gave up and used stimulus-remote https://www.npmjs.com/package/stimulus-remote
I will try your solution.