Debugging JavaScript minification errors (in Lifer

2019-08-27 17:49发布

Liferay 6.2. tries to use best practices and JS minification is one of them.

But what do you do when your unminified JavaScript works and minification produces errors like this (in Tomcat console):

12:23:48,794 ERROR [http-bio-8080-exec-10][MinifierUtil:111] 607: 21: identifier is a reserved word
12:23:48,797 ERROR [http-bio-8080-exec-10][MinifierUtil:111] 608: 45: identifier is a reserved word
12:23:48,802 ERROR [http-bio-8080-exec-10][MinifierUtil:111] 1: 0: Compilation produced 2 syntax errors.
12:23:48,805 ERROR [http-bio-8080-exec-10][MinifierUtil:88] JavaScript Minifier failed for_________    AUI().use('node', 'aui-base', 'aui-io-request', 'aui

[MinifierUtil:111] 607: 21: and [MinifierUtil:111] 608: 45: are not line numbers in your code (jsp/ftl/...) as man expects from console log and googling "identifier is a reserved word" or "JavaScript Minifier failed for_________" helped me almost nothing (ok, I knew about https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords normally).

Pasting code between <script> and </script> to JS lint or hint or any other JS tool is not an option as it contains many JAVA and spring/freemarker/liferay tags etc...

So - my question is - as I wasn't able to find best practices / methodologies for debugging this - what is your opinion (or even better - experience :)) ?

2条回答
forever°为你锁心
2楼-- · 2019-08-27 17:57

I finally managed to solve the problem by:

copying the rendered (and unminified(!)) code between <script> and </script> and paste it to JShint/lint/online minifier and re-check it there,

but I still wonder if there is some better way... (changing server properties from developer to production and back means restarting server few times at least and that takes about 300 seconds (only for restart) on my new(!) i7 vPro 64GB, SSD HDD workstation, so I try to avoid it as much as I can :)).

BTW: unminified code had some "deprecated" but simple ECMA methods that worked normally in JSFiddle and all latest browsers on my Win8.1...

查看更多
▲ chillily
3楼-- · 2019-08-27 18:14

Well, you solved the problem in another way - just some pointers should you (or someone else) run into this issue again:

Minifier reports Line number and Offset in these error messages, but they're related to the content that the minifier sees - e.g. not in your JSP, FTL or other file, but in whatever gets passed to the minifier.

The way to read the minifier log is:

  • Line 607, column 21 as well as Line 608, column 45 have a problem
  • In the following line, you see JavaScript Minifier failed for_________ AUI().use('node', 'aui-base', 'aui-io-request', 'aui which is the first part of the content that the minifier sees - locating this code, you might be able to identify which content gets passed to the minifier and count down the lines (well, jump down 607 lines from there)

Side issues: Agreeing with @Origineil that the startup time rather points to another issue that you have - it shouldn't be that much unless you deliberately have processes running at startup. E.g. if you're running a cluster and each machine keeps its own lucene index, you must reindex at startup. If you want to work around that, two indexes might not be what you're after. But it's only an example, and you didn't ask for this. I just wanted to add some pointers. I assume that you have tuned your JVM memory settings already and are not running with the default bundle's settings?

查看更多
登录 后发表回答