【问题标题】:Action view::template::error (Unexpected token: operator (<))操作视图::template::error(意外标记:运算符 (<))
【发布时间】:2019-02-12 23:19:01
【问题描述】:

我在 heroku 的部署遇到了问题! 我刚刚使用 cedar 堆栈创建了一个应用测试,推送我的应用,我遇到了这个问题(日志)

←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m ActionView::Template::Error (Unexpected token: operator (<)
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m   (in /app/app/assets/javascripts/application.js)):
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m     3: <head>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m     4:   <title>Test</title>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m     5:   <%= stylesheet_link_tag    "application" %>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m     6:   <%= javascript_include_tag "application" %>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m     7:   <%= csrf_meta_tags %>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m     8: </head>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m     9: <body>

有什么想法吗??

更新:

我的 application.js 文件

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

【问题讨论】:

  • application.js 中可能发生了一些奇怪的事情。您是否检查过它在 localhost 中是否正常工作?
  • 是的,在我的本地服务器应用程序工作正常。
  • 它是否在您的本地机器上正常工作在生产模式(预编译资产)? /app/assets/javascript 目录下有非 js/coffee 文件吗?
  • 不,只有 application.js 和 rails 生成的所有 .js.coffee 文件
  • 你有没有解决这个问题?我遇到了同样的错误...

标签: ruby-on-rails heroku


【解决方案1】:

我遇到了这个错误,我花了一段时间才弄清楚清单中引用的哪个文件是罪魁祸首。一旦我弄清楚是哪个文件导致了错误,搜索“>”就会拉出几行,但我很幸运并很快在一个使用 =&gt; 运算符的地图函数中归零:

.map(x =&gt; x.id);

一旦我将其更改为匿名函数:

.map(function(x) { return x.id; });

错误消失了。

【讨论】:

  • 但是如何让rails支持ES7呢?
【解决方案2】:

我刚刚遇到了这个问题,诀窍是服务器和我的本地主机之间还有一条冲突线。在我的本地主机中,一切都很好,但我认为这是因为一些缓存或其他原因。无论如何,我打开了 application.js 并删除了带有 的行

我把它放在这里是为了记录问题和可能的解决方案

【讨论】:

    【解决方案3】:

    注意: OP 提出这个问题已经快 7 年了。我遇到的问题可能是一个较新的问题(与 OP 具​​有相同的错误日志输出)。以下答案可能不适用于 OP 遇到的问题,但可能对寻求解决方案的新访问者有所帮助。 我的 Rails 版本: 5.1.2

    发现问题

    Production 如何处理我的assets.precompile(在config/initializers/assets.rb)是一个问题

    经过反复试验以找到罪魁祸首(我一周前创建的一个新 JS 文件),我注意到在注释掉 config/initializers/assets.rb 中包含该文件的行后错误消失了。

    # Commented out until precompile fix found
    # Rails.application.config.assets.precompile += %w( break_the_project.js )
    

    修复

    因为这对我来说只发生在Production中,所以我更新了config/environments/production.rb,替换了以下行:

    config.assets.js_compressor = :uglifier
    

    到:

    config.assets.js_compressor = Uglifier.new(harmony: true)
    

    重启 Rails 服务器后,我的世界又恢复了平静。

    Source

    【讨论】:

      猜你喜欢
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      相关资源
      最近更新 更多