资产说“未预编译"当它们被预编译时 [英] Assets say "not precompiled" when they are precompiled

查看:129
本文介绍了资产说“未预编译"当它们被预编译时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,尝试使用资产管道时出现此错误.我不明白是什么原因造成的.

Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Photos#show

Showing .../app/views/photos/_photo_view.html.haml where line #2 raised:

jquery.autocomplete isn't precompiled

Extracted source (around line #2):

1: - content_for :scripts do
2:  = javascript_include_tag 'jquery.autocomplete'

但是,这是预编译的.我在启动服务器之前运行了rake assets:precompile RAILS_ENV=production,在我的public/assets目录中有文件:jquery-5550a245a55b28927b5552cac182e612.autocomplete.js.js.gz,它准确地反映在清单中:

#manifest.yml
---
application.js: application-4277323e3f7506b71f45c71e8a3a7c8f.js
jquery.autocomplete.js: jquery-5550a245a55b28927b5552cac182e612.autocomplete.js
jquery.cycle.all.min.js: jquery-183ef696b43944deaee5778d3094dbdd.cycle.all.min.js
jquery.fancybox.js: jquery-e52e44b2b4fb349bade9beb91461a810.fancybox.js
jquery.plupload.queue.js: jquery-f2e7f6ad7d2e5ca50235ed21f8d573cc.plupload.queue.js
jquery.tools.js: jquery-c53e304240fa56767fe0f2a00cb4bceb.tools.js
plupload.full.js: plupload-5dd26ee3fff6b627c19f196e9d1429dd.full.js
application.css: application-ce5217e1714cbc4e9c3ff6c5dfc9b221.css
fancybox.css: fancybox-9ee9c36f391086e4b0629b7df4042390.css
jquery.plupload.queue.css: jquery-661fbf3f503aa32ff11c004838c0820b.plupload.queue.css
jquery.js: jquery-4d23f0cfea862f56deb04f0a8ab1fcee.js
jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js

有问题的javascript文件未加载到我的application.js文件中,因为我只需要在一个视图上使用它,而不在应用程序的其他任何地方使用它.为了解决这个问题(并修复链轮尝试编译sass局部文件的问题),我将预编译正则表达式配置为:

#environments/production.rb
config.assets.precompile = [/^[a-zA-Z]*\..*/]

(上面的正则表达式会预编译任何以字母字符开头的文件,而忽略以下划线之类的非字母字符开头的文件).

有人对导致此问题的原因及其解决方法有任何见解吗?资产管道使我无法胜任!

更新

仅发现Rails.configuration.assets.digests在生产中返回nil.也许是问题所在,由于某些原因,链轮无法找到manifest.yml.

可能是我误会了,但是看起来链轮在寻找manifest.yml时没有在配置中使用assets_host.

https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/railtie.rb#L38

解决方案

尽管设置了config.assets.compile = false,但我自己一直在努力解决问题,因为我怀疑上面的示例将标志设置为true./p>

无法通过管道在本地生产导轨3.1.3服务器上配置资产

根据UberNeet的建议,我的观察结果归结为Sprockets 2.0.3错误.解决方法是从资产名称中删除该期间,或者将其包括在清单中,而不是直接链接至该资产.

关于此的错误报告在这里: https://github.com/rails/rails/issues/3398

看看上面的问题,并根据我过去两天的经验,我怀疑设置config.assets.compile = true时资产命名存在相关问题.此问题可能源于资产命名-您的清单中的jquery.autocomplete库编译为:

jquery-5550a245a55b28927b5552cac182e612.autocomplete.js

但是,当您使用rake assets:precompile通过rake预编译这些资产时,我相信它们实际上已编译为:

jquery.autocomplete-5550a245a55b28927b5552cac182e612.js

可能是这种差异导致了您提到的问题.尽管上面列出了解决方法,但也可能值得提出另一个github问题,并且我知道Rails 3.2将使用Sprockets 2.1.0,它可能已经包含此问题的修复程序.

Ok so, I'm getting this error when I try to use the asset pipeline. I don't understand what's causing it.

Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Photos#show

Showing .../app/views/photos/_photo_view.html.haml where line #2 raised:

jquery.autocomplete isn't precompiled

Extracted source (around line #2):

1: - content_for :scripts do
2:  = javascript_include_tag 'jquery.autocomplete'

However, this IS precompiled. I ran rake assets:precompile RAILS_ENV=production before starting the server, and in my public/assets directory I have the file: jquery-5550a245a55b28927b5552cac182e612.autocomplete.js as well as .js.gz, and it's accurately reflected in the manifest:

#manifest.yml
---
application.js: application-4277323e3f7506b71f45c71e8a3a7c8f.js
jquery.autocomplete.js: jquery-5550a245a55b28927b5552cac182e612.autocomplete.js
jquery.cycle.all.min.js: jquery-183ef696b43944deaee5778d3094dbdd.cycle.all.min.js
jquery.fancybox.js: jquery-e52e44b2b4fb349bade9beb91461a810.fancybox.js
jquery.plupload.queue.js: jquery-f2e7f6ad7d2e5ca50235ed21f8d573cc.plupload.queue.js
jquery.tools.js: jquery-c53e304240fa56767fe0f2a00cb4bceb.tools.js
plupload.full.js: plupload-5dd26ee3fff6b627c19f196e9d1429dd.full.js
application.css: application-ce5217e1714cbc4e9c3ff6c5dfc9b221.css
fancybox.css: fancybox-9ee9c36f391086e4b0629b7df4042390.css
jquery.plupload.queue.css: jquery-661fbf3f503aa32ff11c004838c0820b.plupload.queue.css
jquery.js: jquery-4d23f0cfea862f56deb04f0a8ab1fcee.js
jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js

The javascript file in question is not loaded in my application.js file because I only need it on one view and don't use it anywhere else in the app. To account for that (and to fix sprockets trying to compile sass partials) I configured my precompile regexp like so:

#environments/production.rb
config.assets.precompile = [/^[a-zA-Z]*\..*/]

(The above regexp precompiles any file that starts with a letter character, and ignores files starting with a non-letter character like an underscore).

Does anyone have any insight into what's causing this and how it can be fixed? The asset pipeline is making me pull my hair out!

UPDATE

just found out that Rails.configuration.assets.digests is returning nil in production. maybe the problem is there, for some reason sprockets is not finding the manifest.yml.

Im probably mistaken but seems like sprockets is not using the assets_host in config when looking for the manifest.yml.

https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/railtie.rb#L38

解决方案

I have been wrestling with the problem myself, although with config.assets.compile = false set, as I suspect the example above was with the flag set to true.

Cannot configure assets via pipeline on local production rails 3.1.3 server

My observations came down to it being a Sprockets 2.0.3 bug, as UberNeet suggested towards. The workaround was to either remove the period from the asset name, or include it as part of a manifest, rather than link to it directly.

The bug report for this is here: https://github.com/rails/rails/issues/3398

Looking at your issue above, and tallying it with my experience from the last two days, I suspect there is an associated issue with asset naming when config.assets.compile = true is set. This issue probably stems from the asset naming - your manifest has the jquery.autocomplete library percompiled as:

jquery-5550a245a55b28927b5552cac182e612.autocomplete.js

But when you precompile these assets via rake using rake assets:precompile, I believe they are actually compiled to:

jquery.autocomplete-5550a245a55b28927b5552cac182e612.js

It is probably this discrepancy that is causing the issue you mentioned. Might be worth raising another github issue for this too, although the workarounds are listed above, and I understand that Rails 3.2 will be using Sprockets 2.1.0, which may contain the fix for this issue already.

这篇关于资产说“未预编译"当它们被预编译时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆