trunk icon indicating copy to clipboard operation
trunk copied to clipboard

Minification of some javascript is breaking some functionality.

Open coravacav opened this issue 1 year ago • 4 comments

Running into some issues adding javascript to an app. Without minification, you get image Which seems to be a result of minification.

I've created a relatively minimal reproduction here.

Changing

<script data-trunk src="treesitter/tree-sitter.js"></script>

to

<script data-trunk data-no-minify src="treesitter/tree-sitter.js"></script>

during a release build (otherwise modification in general is disabled) solves the problem.

coravacav avatar Mar 24 '24 01:03 coravacav

A note from further testing: it seems that with serve, only the javascript of the tree-sitter must not be minified. However, when built, the tree-sitter wasm also needs to be minified. This seems to be a well-known issue for treesitter as seen here https://github.com/tree-sitter/tree-sitter/issues/927, however it still seems notable to bring up here because the change in javascript behavior is still probably not ideal.

coravacav avatar Mar 24 '24 01:03 coravacav

I am not sure what the exact problem is. I do recall issues where the JS file was actually a module JS file. That can make a difference. For that you would need to set type="module" (also see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type).

Trunk uses https://github.com/wilsonzlin/minify-js for JS minification (we use 0.5.6, as 0.6.0 also had some issues). So it would make sense to open an issue on that project.

ctron avatar Mar 26 '24 16:03 ctron

I am not sure if there's something that trunk could do better? If so, please let me know.

ctron avatar Apr 23 '24 11:04 ctron

Sorry for not replying sooner.

Adding type="module" changes the error to be

highlighting-b62b1cbd3f28dbb8.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'init')
    at highlighting-b62b1cbd3f28dbb8.js:1:19

I'll also open an issue over there when I find some time, but I am leaving this here for posterity's sake.

coravacav avatar Apr 23 '24 13:04 coravacav

thanks for this, maybe we can close this as there is a workaround for that edge case (does this need a FAQ entry?). @ctron

duke-m avatar May 09 '25 20:05 duke-m

I guess so. Having that would be nice.

ctron avatar May 12 '25 07:05 ctron