Rails 3.1 Asset Pipeline 和 Uglifier 中可能存在的错误
我在 Heroku 上部署时遇到了问题,导致 rake 任务失败。
rake assets:precompile
底部是集成
- Rails 3.1
- Jquery 日历时出现的错误: https://github.com/themouette/jquery-week-calendar
- Twitter bootstrap
错误发生在 uglifier 中。
我怀疑这个问题可能与日历的许多本地化内容有关。
我通过设置解决了该错误:
# Compress JavaScripts and CSS
config.assets.compress = false
在清理临时文件时,我无法检查文件。我也无法让 RubyMine 中的调试器在断点处停止。
如果这是一个错误,有什么想法吗?有什么办法可以让临时文件不被删除吗?任何让 RubyMine 调试器在 rake 任务上工作的方法(是的,尝试了显而易见的方法,使用 EAP 112-291。
提取资产:预编译:所有 RAILS_ENV=生产 RAILS_GROUPS=资产 耙子中止!意外字符 '' (行:21454,列:0,位置: 641761)
错误 在新的 JS_Parse_Error (/tmp/execjs20111231-15374-1fve7h4.js:497:22) 在 js_error (/tmp/execjs20111231-15374-1fve7h4.js:505:15) 在 parse_error (/tmp/execjs20111231-15374-1fve7h4.js:596:17) 在 Object.next_token [作为输入] (/tmp/execjs20111231-15374-1fve7h4.js:839:17) 接下来(/tmp/execjs20111231-15374-1fve7h4.js:943:37) 在 Object.semicolon [as 1] (/tmp/execjs20111231-15374-1fve7h4.js:986:38) 在 prog1 (/tmp/execjs20111231-15374-1fve7h4.js:1527:28) 在 simple_statement (/tmp/execjs20111231-15374-1fve7h4.js:1123:35) 在/tmp/execjs20111231-15374-1fve7h4.js:1031:35 在/tmp/execjs20111231-15374-1fve7h4.js:1510:32
I ran into a problem deploying on Heroku do to a failure in the rake task
rake assets:precompile
At the bottom is the error I get if I integrate
- Rails 3.1
- Jquery calendar: https://github.com/themouette/jquery-week-calendar
- Twitter bootstrap
The error happens from uglifier.
I suspect that problem could be related to the inclusion of many localizations for the calendar.
I worked around the error by setting:
# Compress JavaScripts and CSS
config.assets.compress = false
I was not able to examine the files as the temporary files are cleaned up. I also could not get the debugger in RubyMine to stop at a breakpoint.
Any ideas if this is a bug? Any way to get the temporary files to not get deleted? Any way to make the RubyMine debugger work on the rake task (yes, tried the obvious, using EAP 112-291.
rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted! Unexpected character '' (line: 21454, col: 0, pos:
641761)Error
at new JS_Parse_Error (/tmp/execjs20111231-15374-1fve7h4.js:497:22)
at js_error (/tmp/execjs20111231-15374-1fve7h4.js:505:15)
at parse_error (/tmp/execjs20111231-15374-1fve7h4.js:596:17)
at Object.next_token [as input] (/tmp/execjs20111231-15374-1fve7h4.js:839:17)
at next (/tmp/execjs20111231-15374-1fve7h4.js:943:37)
at Object.semicolon [as 1] (/tmp/execjs20111231-15374-1fve7h4.js:986:38)
at prog1 (/tmp/execjs20111231-15374-1fve7h4.js:1527:28)
at simple_statement (/tmp/execjs20111231-15374-1fve7h4.js:1123:35)
at /tmp/execjs20111231-15374-1fve7h4.js:1031:35
at /tmp/execjs20111231-15374-1fve7h4.js:1510:32
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可能会发现其中一个 js 文件在某处存在语法错误。这可能是块末尾缺少分号,或其他一些小问题。通常浏览器仍然会加载 js 并且它会工作,但是 uglifier 无法压缩它并出现这些错误。我会首先开始查找本地化文件。
找出哪个文件包含错误的一种方法是使用最少的文件集在本地重新预编译,然后逐个添加内容,直到出现错误。如果是由于缺少分号而导致的,则损坏的将是您添加的倒数第二个文件。
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.
如果阅读此线程的任何人在 Rails 应用程序中遇到 unicode 字符或“UTF-8 中的无效字节序列”问题,请尝试将其放入 production.rb 文件中:
在我的情况下,uglifier 正在将我的 javascript 中的字符串转换为
\udbff
转换为 UTF-8 字符í¯¿
这最终破坏了一些 unicode 正则表达式。 (这种情况发生在涡轮链轮和 codemirror 上,但只要您的 javascript 依赖 unicode 字符的 ASCII 表示形式,您就可能会遇到这种情况。)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:
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.)I18N 文件“jquery-ui-i18n.js”在每个注释之前都有一个错误字符。
查看 shell 中带有“more”的前两行,显示错误的字符:
删除该字符后,它可以工作。
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:
After having removed this character it works.