【问题标题】:Javascript Assets Compilation Error on HerokuHeroku 上的 Javascript 资产编译错误
【发布时间】:2014-05-02 03:00:40
【问题描述】:

在我的 application.html.haml 中

=stylesheet_link_tag "application", :media => "all"
=javascript_include_tag "jquery-1.11.0.min"
=javascript_include_tag "jquery-ui-1.10.4.min"
=javascript_include_tag "angular.min"
=javascript_include_tag "angular-route.min"
=javascript_include_tag "angular-resource.min"
=javascript_include_tag "angular-ui-router.min"

这些 js 文件目前在我的 app/assets/javascripts 文件夹中

当我将它部署到 heroku 时,我会继续获取

3848+00:00 app[web.1]:     9:     =stylesheet_link_tag "application", :media => "all"
2014-05-01T21:25:16.063849+00:00 app[web.1]:     10:     =javascript_include_tag "jquery-1.11.0.min.js"
2014-05-01T21:25:16.063846+00:00 app[web.1]: ActionView::Template::Error (html5shiv.js isn't precompiled):
2014-05-01T21:25:15.995499+00:00 app[web.1]: Started GET "/" for 128.31.34.63 at 2014-05-01 21:25:15 +0000
2014-05-01T21:25:16.051098+00:00 app[web.1]:   Rendered home/index.html.haml within layouts/application (10.3ms)
2014-05-01T21:25:16.063843+00:00 app[web.1]: 
2014-05-01T21:25:16.063851+00:00 app[web.1]:     11:     =javascript_include_tag "jquery-ui-1.10.4.min.js"
2014-05-01T21:25:16.063853+00:00 app[web.1]:     12:     =javascript_include_tag "html5shiv.js"
2014-05-01T21:25:16.063854+00:00 app[web.1]:     13:     =javascript_include_tag "angular.min.js"
2014-05-01T21:25:16.063858+00:00 app[web.1]:     15:     =javascript_include_tag "angular-resource.min.js"
2014-05-01T21:25:16.063856+00:00 app[web.1]:     14:     =javascript_include_tag "angular-route.min.js"
2014-05-01T21:25:16.063860+00:00 app[web.1]:   app/views/layouts/application.html.haml:12:in `_app_views_layouts_application_html_haml___1963393475950734090_70074639367120'

我不断收到资产编译错误。我应该在我的 application.js 中要求它们吗?在我的 application.js 我有这些

//= require jquery_ujs
//= require bootstrap
//= require_tree .

我将此添加到我的 config/environments/production.rb

config.assets.precompile += %w(email.css event_creation_dynamic_form.js jquery-1.11.0.min.js jquery-ui-1.10.4.min.js angular.min.js angular-route.min.js)

这对我来说真的不起作用。我不太熟悉 rails 中的资产管道以及 heroku 资产管道的工作原理。我也试过跑步

heroku run rake assets:precompile

我的 javascript 文件也是缩小版。我希望这是用于生产的正确版本。 我是否正确使用了 js include 标签?

【问题讨论】:

    标签: javascript ruby-on-rails heroku


    【解决方案1】:

    看起来 Heroku 已经很方便地告诉你问题出在哪里了:

    ActionView::Template::Error (html5shiv.js isn't precompiled)
    

    所以你需要将该文件添加到预编译数组中,如下所示:

    config.assets.precompile += %w(html5shiv.js, any-other-files-here)
    

    话虽如此,回答你的问题,不,你并没有真正正确使用 js include 标签。

    您应该将这些 js 文件包含在 application.js 中。这样,文件将与 application.js 一起预编译,您不必将它们添加到预编译路径中。例如在 application.js 中:

    //= require path/to/jquery-1.11.0.min.js
    //= require path/to/jquery-ui-1.10.4.min.js
    //= require path/to/angular.min.js
    //= require path/to/angular-route.min.js
    //= require path/to/angular-resource.min.js
    //= require path/to/angular-ui-router.min.js
    

    【讨论】:

    • 实际上我从 assets/javascript 和 js 包含标签中删除了 html5shiv js 文件。我之前有它,但是当我推送它时,它会转到下一件事并说它不是预编译的。如果 heroku 要求它,我会将它添加回来并重试。我会试试你的建议。
    • @Jngai1297 你对 html5shiv.js 的理解太过分了。如果您收到任何文件的预编译错误,则需要将该文件添加到预编译数组; html5shiv.js 只是 Heroku 卡住的文件。
    猜你喜欢
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    • 2016-04-18
    • 1970-01-01
    • 2012-06-26
    • 2015-03-26
    相关资源
    最近更新 更多