bundle exec rake 资产:预编译失败并显示“意外令牌" [英] bundle exec rake assets:precompile fails with `unexpected token`

查看:22
本文介绍了bundle exec rake 资产:预编译失败并显示“意外令牌"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已准备好将我的 Rails 3.1 应用程序部署到生产环境中,并且由于我正在使用资产管道,我需要预编译我的资产.然而,当我尝试这个时,我得到一个明显与编译 jQuery 相关的错误:

I'm ready to deploy my Rails 3.1 app into production, and since I'm using the asset pipeline, I need to precompile my assets. However, when I try this, I get an error apparently related to compiling jQuery:

$ bundle exec rake --trace assets:precompile
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/adam/.rvm/rubies/ruby-1.9.3-p0/bin/ruby /home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
399: unexpected token at '"/*!u000a * jQuery JavaScript Library v1.7.1u000a * http://jquery.com/u000a *u000a * Copyright 2011, John Resigu000a * Dual licensed under the MIT or GPL Version 2 licenses.u000a * http://jquery.org/licenseu000a *u000a * Includes Sizzle.jsu000a * http://sizzlejs.com/u000a * Copyright 2011, The Dojo Foundationu000a * Released under the MIT, BSD, and GPL Licenses.u000a *u000a * Date: Mon Nov 21 21:11:03 2011 -0500u000a */u000afunction addActiveScaffoldPageToHistory(a,b){if(typeof

[剪下很多东西]

  (in /data/music/RotC/eventbook/app/assets/javascripts/application.js)
/home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/gems/json-1.6.4/lib/json/common.rb:148:in `parse'
/home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/gems/json-1.6.4/lib/json/common.rb:148:in `parse'
/home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/gems/multi_json-1.0.4/lib/multi_json/engines/json_common.rb:9:in `decode'
/home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/gems/multi_json-1.0.4/lib/multi_json.rb:76:in `decode'
/home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:61:in `extract_result'
/home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:27:in `block in exec'
/home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:40:in `compile_to_tempfile'
/home/adam/.rvm/gems/ruby-1.9.3-p0@rails-3.1/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:26:in `exec'

[剪下更多的东西]

这是我的 application.js:

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//
// N.B. jQuery requires have to come before this:
//= require active_scaffold

我使用的是默认压缩器,即 uglifier.

I'm using the default compressor, i.e. uglifier.

我发现如果我在 config/environments/production.rb 中将 config.assets.compress 更改为 false 那么它就可以工作很好,但当然,如果我能想出一种方法将其保持为 true,我的应用程序会表现得更好.

I've found that if I change config.assets.compress to false in config/environments/production.rb then it works fine, but of course my app would perform better if I could figure out a way to keep it as true.

我看过耙子资产:预编译不起作用(rails 3.1.1) 并且我不认为它是重复的,因为错误是 undefined: Unexpected token: operator (<).

I've looked at rake assets:precompile doesn't work (rails 3.1.1) and I don't think it's a duplicate because the error is undefined: Unexpected token: operator (<).

有什么想法吗?我隐约怀疑 jQuery 代码中的那些 unicode 字符,但我不确定如何证明或反驳它们导致了问题.

Any ideas? I'm vaguely suspicious of those unicode characters in the jQuery code, but I'm not sure how to prove or disprove that they are causing the problem.

推荐答案

我遇到了这个完全相同的问题并解决了它,详细信息如下:

I had this exact same problem and solved it, here are the details:

当您使用 application.js 和 //= require ... 在 Rails 3.1 环境中包含一个或多个 javascript 文件时,Rails 将用 < 包装您的文件内容;脚本>..filecontents.. </script>.您可以通过在开发模式下运行您的站点并执行 View | 来验证这一点.来源.

When you include one or more javascript files in your Rails 3.1 environment using application.js and //= require ..., Rails will wrap the contents of your file with a <script> ..filecontents.. </script>. You can verify this by running your site in development mode and doing a View | Source.

问题是,在开发模式下,如果您实际使用该脚本,它可能看起来工作正常.但是,本质上,您拥有的是

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆