【问题标题】:Rails bower doesn't compileRails bower 无法编译
【发布时间】:2014-09-11 18:18:10
【问题描述】:

我的 Rails 解决方案使用 Bower 来管理我的前端库。 我跟着this tutorial 设置它。 它正在工作,但是当我尝试预编译它时,它会出现以下错误:

RAILS_ENV=production bundle exec rake assets:precompile
rake aborted!
ExecJS::ProgramError: Unexpected token: eof (undefined) (line: 46, col: 0, pos: 1406)

Error
    at new JS_Parse_Error (/tmp/execjs20140911-20410-llghcjjs:2357:10623)
    at js_error (/tmp/execjs20140911-20410-llghcjjs:2357:10842)
    at croak (/tmp/execjs20140911-20410-llghcjjs:2357:19067)
    at token_error (/tmp/execjs20140911-20410-llghcjjs:2357:19204)
    at unexpected (/tmp/execjs20140911-20410-llghcjjs:2357:19292)
    at block_ (/tmp/execjs20140911-20410-llghcjjs:2357:24537)
    at ctor.body (/tmp/execjs20140911-20410-llghcjjs:2357:24191)
    at function_ (/tmp/execjs20140911-20410-llghcjjs:2357:24256)
    at expr_atom (/tmp/execjs20140911-20410-llghcjjs:2357:27308)
    at maybe_unary (/tmp/execjs20140911-20410-llghcjjs:2357:29977)
  (in /home/augustopedraza/Documents/Projects/BuscoHogar/landing-page/vendor/assets/bower_components/jquery/src/intro.js)

知道怎么解决吗?

提前致谢!!!

【问题讨论】:

  • 46 of /home/augustopedraza/Documents/Projects/BuscoHogar/landing-page/vendor/assets/bower_components/jquery/src/intro.js 的行是什么?
  • 这是Bower运行后下载的jQuery代码:rake bower:install

标签: ruby-on-rails ruby ruby-on-rails-4 assets bower


【解决方案1】:

我遇到了同样的问题..我发现这是因为通常压缩资产..所以临时修复将在 config/environments/production.rb 中注释此行:

config.assets.js_compressor = :uglifier

我目前不知道是uglifier本身在压缩JS文件后导致错误还是JS有问题。我目前正在探索 js 压缩的其他替代方案,看看它是否可以工作.. P.S.我也在使用 bower 组件,所以可能是 bower + uglifier 导致错误

【讨论】:

  • 是的,评论这条线对我有用,你找到合适的修复方法或替代的丑陋器了吗?
【解决方案2】:

我可以通过编辑文件 intro.js 来解决这个问题。产生错误的行是:

 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ){

改成

}(typeof window !== "undefined" ? window : this, function( window, noGlobal ){}));

您现在可能会收到 outro.js 的错误,它只包含缺少的

}));

只需将其删除,一切都会编译。我没有对它进行广泛的测试,但我没有注意到由于这些变化而导致 jquery 中断的任何事情。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 2012-03-26
  • 1970-01-01
  • 2017-11-05
  • 2014-04-20
相关资源
最近更新 更多