I have a rails project and only in production (works fine locally in development), imported JS modules apparently do not load, and I get console errors referencing 404 errors for the files:
**Error: 404 Not Found** https://example.com/assets/controllers/meeting/modules/shared_helpers **imported from** https://example.com/assets/controllers/meeting/parent-file-xxxxxxxxxxxxxxxxx.js
The fingerprinted version of the files do exist in the public folder. However the console errors are not referencing them:
‘GET
https://example.com/assets/controllers/meeting/modules/shared_helpers’
The parent JS file that is importing the JS modules seems to work. In the console it’s referred to by its finger printed name: ‘https://example.com/assets/controllers/meeting/parent-file-xxxxxxxxxxxxxxxxx.js’
In that main parent JS file, the imports look like this:
import sharedHelpers from './modules/shared_helpers';
where shared_helpers.js is located in exampleappjavascriptcontrollersmeetingmodules and the file that is importing it is in exampleappjavascriptcontrollersmeeting
Things I’ve tried:
I’ve already updated production.rb:
config.public_file_server.enabled = true
Then ran
‘rake assets:precompile’
I’ve clobbered the public folder and recompiled and replaced
I added this to nginx conf
location ~ ^/assets/ {
root /home/ec2-user/example/public;
gzip_static on;
expires max;
add_header Cache-Control public;
}
Importmap.rb looks like:
pin "application", to: "application.js", preload: true
# Hotwired libraries
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
# Stimulus controllers
pin_all_from "app/javascript/controllers", under: "controllers"
# Meeting modules
pin_all_from "app/javascript/controllers/meeting/modules", under: "controllers/meeting/modules"
# External libraries
pin "meeting-client", to: "https://xxx.esm.mjs"m"
I’ve tried:
Why does Rails give 404 error for all assets?
Rails 7 and Import-map and loading custom JS file
EDIT
Should also mention I’m using secure-headers gem (csp), which has been .
SecureHeaders::Configuration.override(:disable_csp) do |config|
config.csp = SecureHeaders::OPT_OUT
end