【问题标题】:Debugging Rails 3.2 failing to precompile ember-rails 0.19调试 Rails 3.2 无法预编译 ember-rails 0.19
【发布时间】:2015-07-14 15:27:19
【问题描述】:

寻找一种方法来确定此错误来自我的代码或 ember-rails/ember-rails-source 的何处。使用 rails 3.2 和最新的 ember-rails 0.19。当我预编译我的资产时,我遇到了这个错误:

Unexpected token: operator (!) (line: 16, col: 178179, pos: 178546)

Error
    at new JS_Parse_Error (<eval>:3096:22)
    at js_error (<eval>:3104:15)
    at croak (<eval>:3557:17)
    at token_error (<eval>:3564:17)
    at unexpected (<eval>:3570:17)
    at Object.semicolon [as 1] (<eval>:3590:51)
    at prog1 (<eval>:4133:29)
    at simple_statement (<eval>:3726:35)
    at <eval>:3634:35
    at block_ (<eval>:3822:32)
  (in /Users/sjustin/Development/my-app/app/assets/javascripts/application.js.coffee)

我已经能够通过删除我的 application.js.coffee 中的 Ember Sprockets 引用 #= require ember 来破坏性地获取要预编译的资产:

#= require jquery
#= require jquery_ujs
#= require ember
#= require ember-data
#= require_self
#= require my-app

window.MyApp = Ember.Application.create()

但这会破坏应用程序。如果我在本地运行应用程序而不进行预编译,我不会从 Rails 或 JavaScript 控制台收到任何错误。

【问题讨论】:

    标签: ruby-on-rails ember.js asset-pipeline sprockets ember-rails


    【解决方案1】:

    您使用的是哪个 javascript 运行时(例如 therubyracerexecjsnodejs)?你试过换吗?我建议使用 node(特别是如果您在单个服务器上运行多个应用程序),因为如果安装了 node,您不必添加 gem。

    【讨论】:

    • 有趣。我之前没有注意到这一点,但我们在主要的默认 Gemfile 组中使用了therubyracer,在 assets Gemfile 组中使用了execjs。当我尝试预编译时,我没有设置组,想知道它是否与此有关。去看看吧。
    • 使用所有三个相同的问题,输出都相似,但 execjs 给了我一个失败的文件输出:at new JS_Parse_Error (/private/var/folders/rl/5q_8gb4s453fwpy1wnb7cpd52cpx91/T/execjs20150715-72034-17hdmvr.js:3096:22) 但没有帮助,因为它在我看到它之前就消失了。
    • 您可以尝试在您的开发环境中调用rake assets:precompile 吗?而且 - 只是为了确定 - 在本地打开网站时,您的浏览器开发工具中是否有任何 JS 错误?
    • rake assets:precompile 在本地失败并出现同样的错误,但 RAILS_ENV=development rake assets:precompile 不会失败。如果我不预编译并运行该应用程序,则没有错误。但是,如果我使用RAILS_ENV=development 运行它,我会在控制台中得到一个带有Uncaught ReferenceError: MyApp is not defined 的空白页面。感谢您的回复!
    • 搅动锅的东西太多让这个问题很混乱,谢谢大家的帮助!我们的应用程序只有config/environments/production.rb 中的config.assets.compress = true。当我运行RAILS_ENV=development rake assets:precompile 时,控制台错误是由于期望通过 Nginx 提供的资产,而不是请求期间的资产管道。长话短说,JavaScript 中的某个地方存在错误,仅在压缩期间导致错误。除非您设置环境,否则默认为生产环境。
    猜你喜欢
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多