I am working on adding javascript handling to a rails 7 app. I want to use import maps to import external libraries for turbo and stimulus. The current issue I’m having trouble with is that javascript_importmap_tags
is adding an unusable link to my application:
<link rel="modulepreload" href="/application.js">
This gives me this error :
GET http://localhost:3000/application.js net::ERR_ABORTED 404 (Not Found)
I have an application.js file in app/javascript
. I don’t understand why the call to javascript_importmap_tags
is creating a link to a nonexistent javascript file at the application root. I think I must be missing a step somewhere. What do I need to do to make the application.js file load?
This is my importmap.rb file:
pin "application"
and my application.js file is currently just comments:
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
// import "stimulus.min.js"
// import "stimulus-loading.js"
// import "controllers"
// import "@hotwired/turbo-rails"
Please feel free to look at the source for the application here:
https://github.com/fredwillmore/climate-control