资产在预编译时说“未预编译”

时间:2022-10-13 20:38:26

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:

但是,这是预先编译的。我运行了rake资产:在启动服务器之前预先编译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

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:

我的application.js文件中没有加载有问题的javascript文件,因为我只需要在一个视图上使用它,并且不要在应用程序的任何其他地方使用它。为了解释这一点(并修复链接尝试编译sass部分)我配置了我的预编译regexp,如下所示:

#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).

(上面的regexp预编译任何以字母字符开头的文件,并忽略以非字母字符开头的文件,如下划线)。

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.

刚刚发现Rails.configuration.assets.digests在生产中返回nil。也许问题出在那里,由于某种原因,链轮没有找到manifest.yml。

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

我可能错了,但看起来sprockets在查找manifest.yml时没有在config中使用assets_host。

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

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

3 个解决方案

#1


4  

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.

我自己一直在努力解决这个问题,虽然配置了config.assets.compile = false,因为我怀疑上面的例子是将标志设置为true。

Cannot configure assets via pipeline on local production rails 3.1.3 server

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

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.

我的观察归结为它是一个Sprockets 2.0.3错误,正如UberNeet建议的那样。解决方法是从资产名称中删除期间,或将其作为清单的一部分包括在内,而不是直接链接到它。

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

这里的错误报告在这里: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:

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

jquery-5550a245a55b28927b5552cac182e612.autocomplete.js

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

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

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.

可能是这种差异导致了您提到的问题。可能值得为此提出另一个github问题,虽然上面列出了变通方法,我知道Rails 3.2将使用Sprockets 2.1.0,它可能已包含此问题的修复程序。

#2


16  

Add the .js to

添加.js

javascript_include_tag 'jquery.autocomplete.js'

javascript_include_tag'jquery.autocomplete.js'

Seems like there is an missing functionality. When the filename has a period '.' in the name, the .js extension will not get added when looking into the digest.

似乎缺少功能。当文件名具有句点'。'时在名称中,查看摘要时不会添加.js扩展名。

I did some debugging to Sprockets::Helpers::RailsHelper and it seems like digest_for methods gets the logical path without the .js.

我对Sprockets :: Helpers :: RailsHelper进行了一些调试,似乎digest_for方法获得了没有.js的逻辑路径。

#3


0  

Be shure that it isn't required before in application.js for example.

例如,在application.js中之前不需要它。

#1


4  

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.

我自己一直在努力解决这个问题,虽然配置了config.assets.compile = false,因为我怀疑上面的例子是将标志设置为true。

Cannot configure assets via pipeline on local production rails 3.1.3 server

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

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.

我的观察归结为它是一个Sprockets 2.0.3错误,正如UberNeet建议的那样。解决方法是从资产名称中删除期间,或将其作为清单的一部分包括在内,而不是直接链接到它。

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

这里的错误报告在这里: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:

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

jquery-5550a245a55b28927b5552cac182e612.autocomplete.js

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

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

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.

可能是这种差异导致了您提到的问题。可能值得为此提出另一个github问题,虽然上面列出了变通方法,我知道Rails 3.2将使用Sprockets 2.1.0,它可能已包含此问题的修复程序。

#2


16  

Add the .js to

添加.js

javascript_include_tag 'jquery.autocomplete.js'

javascript_include_tag'jquery.autocomplete.js'

Seems like there is an missing functionality. When the filename has a period '.' in the name, the .js extension will not get added when looking into the digest.

似乎缺少功能。当文件名具有句点'。'时在名称中,查看摘要时不会添加.js扩展名。

I did some debugging to Sprockets::Helpers::RailsHelper and it seems like digest_for methods gets the logical path without the .js.

我对Sprockets :: Helpers :: RailsHelper进行了一些调试,似乎digest_for方法获得了没有.js的逻辑路径。

#3


0  

Be shure that it isn't required before in application.js for example.

例如,在application.js中之前不需要它。