I have a rails app that has javascript working correctly locally but when I push to Heroku it's getting 404s for each of the relative imports in my application.js file:
// Simply importing activates Turbo Drive
import "@hotwired/turbo-rails";
import { Application } from "@hotwired/stimulus";
// Here we use relative imports so these aren't in import map
import HelloController from "./application/hello_controller";
import "./application/logstuff";
import "./application/main";
// Start Stimulus and register controllers
window.Stimulus = Application.start();
window.Stimulus.debug = false; // set true to enable stimulus debugging
Stimulus.register("hello", HelloController);
I have my javascript in app/javascript but the error messages read like the javascript is missing from app/assets/:
GET <url>/assets/application/hello_controller net::ERR_ABORTED 404
Am I missing a config somewhere to switch where to look for the javascript?
Thanks :)
I had a similar issue and resolved it by changing the contents of my app/javascript/controllers/index.js file to this:
import { application } from "controllers/application"
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)
More info here -> https://github.com/hotwired/stimulus-rails/issues/87
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With