Skip to content

sourceMappingURL missing in prod using sprockets and esbuildΒ #93

Closed
@sedubois

Description

@sedubois

Thank you for this new gem! I'm trying to get source maps working, I apologize in advance if I misunderstood (I have a limited understanding of front-end tooling).

Source maps do seem to work in our Rails 7 app in development (using sprockets 4.0.2, sprockets-rails 3.4.2, jsbundling-rails 1.0.1 and esbuild 0.14.23): assets:precompile generates a JS bundle with a sourceMappingURL clause at the end. However they do not seem to work in production: the sourceMappingURL clause is absent in this case.

Because of this we do not have proper Javascript crash reports in our monitoring system.

We have this under package.json's scripts: "build": "esbuild app/javascript/*.* --bundle --sourcemap --target=es2016 --minify --outdir=app/assets/builds". I've tried with both config.assets.debug = false (as suggested) and config.assets.debug = true in application.rb, but this does not seem to change the situation. Some debug info below (point 3 is problematic).

  1. When running that esbuild command, two files are generated as expected: app/assets/builds/application.js and app/assets/builds/application.js.map, where the last line of the JS file is //# sourceMappingURL=application.js.map.

  2. When running RAILS_ENV=development bin/rails assets:precompile, two files are generated: public/assets/application-cc3245bb241eac905dc4ffd8a5abc8d3d42445e9e1986ea93ba7b267e583f1cf.js and public/assets/application.js-67cdc37aff88978cfa5a2cdba39ef49c3da8d9b6ff16f4c7eca581548009fe0c.map, and the last lines of the JS file are (which seem correct):

//# sourceMappingURL=/assets/application.js-67cdc37aff88978cfa5a2cdba39ef49c3da8d9b6ff16f4c7eca581548009fe0c.map
//!
;
  1. When running RAILS_ENV=production bin/rails assets:precompile, two files are generated: public/assets/application-6c7fc839b49f22a88c3f45c04cde931d8a6801ad0312f478165ac605915c1d55.js and public/assets/application.js-67cdc37aff88978cfa5a2cdba39ef49c3da8d9b6ff16f4c7eca581548009fe0c.map. However the JS file has no sourceMappingURL statement at the end, it ends with //!.

Is there a way to make source maps work with jsbundling-rails and esbuild?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions