Rails 3.1 Possible Bug in Asset Pipeline and Uglifier

跟風遠走 提交于 2019-12-01 19:48:59

You will probably find that one of you js files has a syntax error somewhere. This could be a missing semicolon at the end of a block, or some other minor problem. Often browsers will still load the js and it will work, but uglifier cannot compress it with those errors. I would start looking in the localisation files first.

One way to find out which file contains the error is to re precompile locally with a minimal set of files and add things one by one until it breaks. If it is due to a missing semicolon, the breakage will the second-last file you added.

Mine precompiled after I removed a stray "debugger" statement. Woops.

If anyone reading this thread encounters issues with unicode characters or "invalid byte sequence in UTF-8" in your rails app, try putting this in your production.rb file:

# override default uglifier options so we don't mangle unicode
  config.assets.js_compressor = Uglifier.new(output: {ascii_only: true})

In my case, the uglifier was converting strings in my javascript like \udbff into UTF-8 characters í¯¿ which ultimately was breaking some unicode regex. (This was happening with turbo-sprockets and codemirror but you might encounter it anytime your javascript relies on ASCII representations of unicode characters.)

The I18N file "jquery-ui-i18n.js" has a bad character before each comment.

Looking at the first two lines with "more" in a shell, shows the wrong character:

<U+FEFF>/* Afrikaans initialisation for the jQuery UI date picker plugin. */
/* Written by Renier Pretorius. */

After having removed this character it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!