Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku Rails 7 deployment not finding Javascript files (404)

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 :)

like image 508
Becky Green Avatar asked Oct 27 '25 08:10

Becky Green


1 Answers

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

like image 160
Buck3000 Avatar answered Oct 28 '25 22:10

Buck3000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!