2
ActionController::RoutingError (No route matches [GET] "/assets/application.js-1246371c75312771378dc97fa604ef404c73f9b477b5eb8f4c6ebb2fd2e1e323.map"):

My build script in package.json is:

"build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds",

So I see under assets, under builds, my application.js, and my application.js.map

But developer console shows 404 on the source map, and the server logs show that resource as an error. What am I doing wrong?

David Lazar
  • 10,865
  • 3
  • 25
  • 38
  • have you tried `rake webpacker:clobber` and `rake webpacker:compile` to compile everything again? – Marelons Jan 17 '22 at 10:49
  • I am not using webpacker. The whole point of this exercise is to use esbuild. – David Lazar Jan 17 '22 at 16:58
  • I'm having the same problem. Did you resolve this? Thanks – nikmak Jan 26 '22 at 21:45
  • Nope. I just remove the --sourcemap from the ESBuild as it clearly does not work for whatever reason. Maybe a newer version will fix that someday. For now though, that solved my problem. – David Lazar Jan 26 '22 at 23:01
  • oh, got the same issue.... but removing the --sourcemap didn't change anything. but there is a corresponding .map file created, it just doesn't have the long timestamp, file is named "application-esbuild.js.map", but browser tries to get "application-esbuild.js-23a1629fa27d6de04ef39a3ad6fdfdec018b3d3ffdc238508aab65be1240dc3e.map" – user14169 Feb 03 '22 at 11:04
  • 1
    So do you think this is solvable? – David Lazar Feb 03 '22 at 16:18

2 Answers2

2

Corresponding to this thread

Setting config.assets.debug = false will solve that error

Artem P
  • 138
  • 7
1

The config.assets.debug = false workaround has undesirable side effects. Missing debug log messages etc.

A cleaner solution is to add the following route definition to config/routes.rb:

if Rails.env.development?
  redirector = ->(params, _) { ApplicationController.helpers.asset_path("#{params[:name].split('-').first}.map") }
  constraint = ->(request) { request.path.ends_with?(".map") }
  get "assets/*name", to: redirect(redirector), constraints: constraint
end

This resolves the sourcemaps for JS and CSS files and keeps asset debugging intact.

wintersolutions
  • 5,173
  • 5
  • 30
  • 51