Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sourceMappingURL missing in prod using sprockets and esbuild #93

Closed
sedubois opened this issue Feb 25, 2022 · 2 comments
Closed

sourceMappingURL missing in prod using sprockets and esbuild #93

sedubois opened this issue Feb 25, 2022 · 2 comments

Comments

@sedubois
Copy link

sedubois commented Feb 25, 2022

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?

@silva96
Copy link

silva96 commented Jan 13, 2023

I found that removing: --public-path=assets in the package.json solves everything. I don't know why, I don't even know what is that for.

But it solves it.

silva96 added a commit to silva96/ai_stories that referenced this issue Jan 13, 2023
@richardkmiller
Copy link
Contributor

@silva96 See #58 for why --public-path=assets is desirable, but it indeed breaks sourcemaps. I've submitted rails/sprockets-rails#515 to fix this in Sprockets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants