Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery bundle exec rake资产:预编译失败,带有“意外令牌”`_Jquery_Ruby On Rails_Deployment_Ruby On Rails 3.1_Web Deployment - Fatal编程技术网

Jquery bundle exec rake资产:预编译失败,带有“意外令牌”`

Jquery bundle exec rake资产:预编译失败,带有“意外令牌”`,jquery,ruby-on-rails,deployment,ruby-on-rails-3.1,web-deployment,Jquery,Ruby On Rails,Deployment,Ruby On Rails 3.1,Web Deployment,我已经准备好将Rails 3.1应用程序部署到生产环境中,因为我正在使用资产管道。但是,当我尝试此操作时,我发现一个明显与编译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/.r

我已经准备好将Rails 3.1应用程序部署到生产环境中,因为我正在使用资产管道。但是,当我尝试此操作时,我发现一个明显与编译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.1\u000a * http://jquery.com/\u000a *\u000a * Copyright 2011, John Resig\u000a * Dual licensed under the MIT or GPL Version 2 licenses.\u000a * http://jquery.org/license\u000a *\u000a * Includes Sizzle.js\u000a * http://sizzlejs.com/\u000a * Copyright 2011, The Dojo Foundation\u000a * Released under the MIT, BSD, and GPL Licenses.\u000a *\u000a * Date: Mon Nov 21 21:11:03 2011 -0500\u000a */\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

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


我已经看过了,但我不认为它是重复的,因为错误是
未定义:意外的令牌:运算符(我遇到了这个确切的相同的问题并解决了它,下面是详细信息:

当您使用application.js和
/=require…
在Rails 3.1环境中包含一个或多个javascript文件时,Rails将使用
.filecontents…
包装文件内容。您可以通过在开发模式下运行站点并查看源代码来验证这一点

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


然而,当您尝试预编译资产时,编译过程中的某些东西(对不起,我不知道具体是什么)阻塞了“我也遇到了同样的问题

尽管我的javascript文件中没有
标记,但Dave的建议对我帮助很大

我能够在我的
应用程序.js中加载的外部库上发现一条注释:

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

以下是我如何调试的

在本地,运行此

RAILS\u ENV=production bundle exec rake资产:预编译

试着找出它阻塞的地方(阻塞之前的脚本就是你想要查看的文件)


在我的例子中,我有一个文件的结尾是
.js
,而它本应该是
.jsx
,这就是修复它的原因。

你在使用哪个js压缩器?你的应用程序中有什么。js?问题现在用这些更新了。非常感谢你花时间报告这个问题,Dave。事实上,在问了这个问题之后的某个时刻,magica的问题lly为我修复了自己-可能是因为我将Rails升级到了3.2或其中一个gem?但是我接受你的答案,因为对于仍然看到这个问题的人来说,这似乎是一个合理的解决方案。谢谢!我在Rails 3.2中遇到了这个问题。非常有用!没有解决我的问题(除了application.html.erb中的
application javascript include标记外,我没有脚本标记。非常感谢。当我的一个gems include
html
文件中有无效选项卡时,我解决了我的问题。我也遇到了类似的问题,但我意外的标记是
。原来我是在一个应用程序中编写ES6的,该应用程序的标签无效。)idn不支持ES6。如果您想在JavaScript中添加注释,请使用
/***/
/
。感谢您提供的提示。这来自
hotjar
嵌入代码,一些开发人员在添加hotjar时复制了这些代码。