galan / packtag

A JSP Taglib for delivering minified, combined and gzip-compressed resources (JavaScript and CSS).
Apache License 2.0
24 stars 13 forks source link

Debugging pack error #5

Closed dennis-johnson-dev closed 7 years ago

dennis-johnson-dev commented 9 years ago

I'm getting an "Uncaught SyntaxError: Unexpected identifier" in one my packs as I try and pack moment.min.js. Is there a way to debug or find out how to resolve this?

galan commented 9 years ago

Can you elaborate a bit? Which version of pack:tag do you use? Do you use special configuration? If so which Compressor for JS do you use? Did you tried to use the non-minimized version of moment.js, since compressing already manipulated JavaScript might have some issues.

dennis-johnson-dev commented 9 years ago

Sure, we have something like:

`

/bower/moment/2.9.0/min/moment.min.js

</pack:script> `

We're using Packtag version 3.11 and we tried the YUI compressor as well as the default. We also tried min/non-min moment.js. Firefox is saying that there is a missing ')' in an argument list. We also just learned that we get a similar error with immutable.js. Any ideas? Thanks.

pherris commented 9 years ago

I believe this is happening because the minified file we are trying to compress (with minify="false" in packtag) has a line length of 31,865 bytes which (I think) is longer than the default specified by Java's InputStreamReader which causes the file to be partially truncated. I see this in DisabledPackStrategy:

new InputStreamReader(resourceAsStream, charset);

where resourceAsStream is defined in PackTag.java as:

ByteArrayInputStream stream = new ByteArrayInputStream(minifedBuffer.toString().getBytes(UTF_8));

Also, I noticed that with minify set to false, the DisabledPackStrategy is used which extends the CssRewritePackStrategy (even though this is JS) - not sure if that is intended. I should mention that we are using the minify=false to only concatenate the pre minified files in an attempt to work around a different issue packing the non minified file.

galan commented 9 years ago

What I found so far:

From what I can see, I think JSMin isn't able to minify the JavaScript resource. You might try a different PackStrategy, or use the minified version with the option minfy="false".

Thinking about the DisabledPackStrategy, I can't remember why it extends the CssRewritePackStrategy. I think it was for CSS resources, so relative paths inside are normalised. But I can't remember why I used it for JS.