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

Sourcemaps with esbuild not working. #73

Closed
ioev opened this issue Jan 20, 2022 · 4 comments
Closed

Sourcemaps with esbuild not working. #73

ioev opened this issue Jan 20, 2022 · 4 comments

Comments

@ioev
Copy link

ioev commented Jan 20, 2022

I'm actually not sure if this is a problem with jsbundling-rails or bundler, but:

I'm bundling my js/css via esbuild --bundle --watch --sourcemap which results in 2 files being generated in assets/builds, application.js and application.js.map. The application requests these via:
/assets/application.debug-1caabe86ba2a00618598d8d7d5a8fe6c57a594dd7babeec3fe6e3ff3ce9185e1.js
/assets/application.js-4112a73edf43c31165109b2906c7bcda25ff0505d405213d39501087ea154f74.map

The sourcemap url does not exist.

If I look at the bottom of my application.js in the build folder, it ends with:

//# sourceMappingURL=application.js.map

And if I look at the end of the file coming from a server request, it ends with:

//# sourceMappingURL=/assets/application.js-5673ea8258e5021fb9befebfe3f84d5c8ff21ee5fd1e52b4f54b8347a5bbfbbb.map
//!
;

//# sourceMappingURL=application.js-4112a73edf43c31165109b2906c7bcda25ff0505d405213d39501087ea154f74.map

The first source map url works, the second does not. I'm assuming bundler is somehow fixing the existing sourcemap definition, but then also adding it's own?

Running esbuild without --sourcemaps ends up with sourcemaps that work on the client, but they are not useful.

Is there a workflow that will work here?

@jdbann
Copy link

jdbann commented Jan 25, 2022

@ioev I had this too, but digging around other esbuild issues led me to this fix which worked for me: #40 (comment)

@dhh
Copy link
Member

dhh commented Jan 25, 2022

For others, you must set config.assets.debug = false.

@dhh dhh closed this as completed Jan 25, 2022
@ioev
Copy link
Author

ioev commented Jan 25, 2022

This fix in conjunction with:
#40 (comment)

allows the sourcemaps to be located, but they still don't seem to actually work in the browser.

I also tried --entry-names=[dir]/[name]-[hash].digested in esbuild, which generates .digested.js files that sprockets can't even locate.

ActionView::Template::Error (The asset "application.js" is not present in the asset pipeline.

(Rails 6.1.4.1 and Sprockets 4.0.2/Sprockets-rails 3.4.2 btw)

@dhh
Copy link
Member

dhh commented Jan 25, 2022

You need to using sprockets-rails 3.4.2+ for this to work.

Gweaton added a commit to UKGovernmentBEIS/beis-report-official-development-assistance that referenced this issue Jan 5, 2023
This was outputting an `application.debug-[fingerprint].js` file, which
was causing a lot of confusion. [This
issue](rails/jsbundling-rails#73) had the
solution for why it was happening. I don't think there's much benefit to
outputting the `.debug` file if we're going to minify the JS (coming in
the next commit), so I've turned it off.
Gweaton added a commit to UKGovernmentBEIS/beis-report-official-development-assistance that referenced this issue Jan 5, 2023
This was outputting an `application.debug-[fingerprint].js` file, which
was causing a lot of confusion. [This
issue](rails/jsbundling-rails#73) had the
solution for why it was happening. I don't think there's much benefit to
outputting the `.debug` file if we're going to minify the JS (coming in
the next commit), so I've turned it off.
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

3 participants