Ruby on rails 编译rails资源时出错

Ruby on rails 编译rails资源时出错,ruby-on-rails,ruby,Ruby On Rails,Ruby,我正试图整理我的资产,以便将我的项目投入生产。 执行此命令时: rake资产:预编译——跟踪RAILS\u ENV=production 我得到以下错误: ** Invoke assets:precompile (first_time) ** Invoke assets:environment (first_time) ** Execute assets:environment ** Invoke environment (first_time) ** Execute environment *

我正试图整理我的资产,以便将我的项目投入生产。 执行此命令时:

rake资产:预编译——跟踪RAILS\u ENV=production

我得到以下错误:

** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
rake aborted!
ExecJS::ProgramError: identifier '    (function(options) {
      function comments(option) {
        if (Object' undefined
(execjs):1
/usr/local/bundle/gems/execjs-2.6.0/lib/execjs/duktape_runtime.rb:29:in `call_prop'
/usr/local/bundle/gems/execjs-2.6.0/lib/execjs/duktape_runtime.rb:29:in `call'
/usr/local/bundle/gems/uglifier-2.7.2/lib/uglifier.rb:212:in `run_uglifyjs'
/usr/local/bundle/gems/uglifier-2.7.2/lib/uglifier.rb:179:in `compile'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/uglifier_compressor.rb:52:in `call'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/uglifier_compressor.rb:28:in `call'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/loader.rb:44:in `load'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in `yield'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:134:in `block in find'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:133:in `each'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:133:in `find'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:168:in `compile'
/usr/local/bundle/gems/sprockets-rails-3.0.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/usr/local/bundle/gems/sprockets-3.5.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/bundle/gems/sprockets-rails-3.0.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/usr/local/bundle/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/usr/local/bundle/bin/rake:16:in `load'
/usr/local/bundle/bin/rake:16:in `<main>'
Duktape::ReferenceError: identifier '    (function(options) {
      function comments(option) {
        if (Object' undefined
/usr/local/bundle/gems/execjs-2.6.0/lib/execjs/duktape_runtime.rb:29:in `call_prop'
/usr/local/bundle/gems/execjs-2.6.0/lib/execjs/duktape_runtime.rb:29:in `call'
/usr/local/bundle/gems/uglifier-2.7.2/lib/uglifier.rb:212:in `run_uglifyjs'
/usr/local/bundle/gems/uglifier-2.7.2/lib/uglifier.rb:179:in `compile'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/uglifier_compressor.rb:52:in `call'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/uglifier_compressor.rb:28:in `call'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/loader.rb:44:in `load'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in `yield'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:134:in `block in find'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:133:in `each'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:133:in `find'
/usr/local/bundle/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:168:in `compile'
/usr/local/bundle/gems/sprockets-rails-3.0.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/usr/local/bundle/gems/sprockets-3.5.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/bundle/gems/sprockets-rails-3.0.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/bundle/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/usr/local/bundle/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/usr/local/bundle/bin/rake:16:in `load'
/usr/local/bundle/bin/rake:16:in `<main>'
Tasks: TOP => assets:precompile
这是在浏览器中打开页面时出现的错误:

(index):21 GET http://dev.nutrimais.com.br/assets/application-c69ac193f2f610776253a81e6da332ce0bb1141cac0141b0d50c686d872126a5.css 
application-541957df4066a1b6e019883423b470301accf44038125390a3908dcf374e1a2b.js:1 Uncaught Error: ExecJS::ProgramError: identifier '    (function(options) {
      function comments(option) {
        if (Object' undefined
  (in (execjs):1)(anonymous function) @ application-541957df4066a1b6e019883423b470301accf44038125390a3908dcf374e1a2b.js:1
(index):54 Uncaught ReferenceError: $ is not defined(anonymous function) @ (index):54
(index):151 Uncaught ReferenceError: $ is not defined

刚刚发现,如果我使用rakeassets:precompile--trace,它会编译。但是使用rake-assets:precompile--trace-RAILS\u-ENV=production它会给我带来错误

您的Javascript在comments函数中有一个bug。修复该问题,应用程序将编译!如果你能发布这个函数,我很乐意看一看。

把它放在你的文件中:

 group :production do
      gem 'therubyracer'
    end

你的JS中有一个bug。加载页面时,浏览器开发人员工具中没有出现任何错误吗?是的,给出了错误:未捕获错误:ExecJS::ProgramError:identifier'(函数(选项){函数注释(选项){如果(对象)未定义(在(ExecJS):1)未捕获引用错误:$is not defined
$is not defined
可能表明您的javascript文件中缺少jQuery。jQuery在javascript文件中…如果您在资产编译中遇到语法错误,则意味着您在打开页面时浏览器中会出现错误。您能帮我们一个忙并打开在浏览器中翻页并在问题中粘贴带有回溯的错误?javascript在上面的问题中…发生了什么事?为什么我会出现这个错误?@Fredericonovakamaralpereir如果你不知道资产编译与javascript有什么关系,那么你应该转到
 group :production do
      gem 'therubyracer'
    end