[英]Why does Rails fails to boot with "Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)"?
After bundle update
my Rails app fails to boot with: bundle update
后,我的 Rails 应用程序无法启动:
Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)
Looks like you've upgraded sprockets.看起来你已经升级了链轮。 The later version(s) of sprockets require what's called a manifest.js
file.更高版本的 sprocket 需要所谓的manifest.js
文件。 You don't have one.你没有。 You need to create one, and add in a few "directives".您需要创建一个,并添加一些“指令”。
In the old version of sprockets, big assumptions were made about what assets to bundle/concatenate - this is what sprockets does btw.在旧版本的 sprockets 中,对捆绑/连接哪些资产做出了很大的假设——顺便说一句,这就是 sprockets 所做的。 things were implicit.事情是隐含的。 The latest changes are a step in the right direction: now you have to tell sprockets explicitly , what files you want bundled and/or concatenated: this is done in your manifest.js file eg:最新的更改是朝着正确方向迈出的一步:现在您必须明确告诉 sprockets,您想要捆绑和/或连接哪些文件:这是在您的 manifest.js 文件中完成的,例如:
"Sprockets, please" “链轮,请”
abc
together将文件夹abc
中的所有内容捆绑在一起xyz
捆绑并连接文件夹xyz
中的所有内容admin.js
separate.保持admin.js
分开。Create the manifest.js file创建 manifest.js文件
$ mkdir -p app/assets/config $ touch app/assets/config/manifest.js (not the root rails directory)
Then copy and paste the following into the manifest.js file you just created:然后将以下内容复制并粘贴到您刚刚创建的 manifest.js 文件中:
//= link_tree../images //= link_directory../javascripts.js //= link_directory../stylesheets.css
Those funny commenty things above //=
are called "directives". //=
上面那些有趣的注释内容被称为“指令”。 It's best if you head on over to the sprockets documentation and please, if you aren't familiar with it, learn how to configure it properly.最好继续阅读sprockets文档,如果您不熟悉它,请学习如何正确配置它。 But i'll provide a small example below:但我将在下面提供一个小例子:
Let's translate the //= link_directory../javascripts.js
directive:让我们翻译//= link_directory../javascripts.js
指令:
"grab every js
file in the javascripts directory, concatenate them, and keep them as SEPARATE javascript files ie no bundling." “抓取 javascripts 目录中的每个js
文件,将它们连接起来,并将它们保存为单独的 javascript 文件,即不捆绑。” If you want bundling, use a different directive.如果要捆绑,请使用不同的指令。 You should also have a javascript_include_tag
, which is typically placed in your application.html.erb
file.您还应该有一个javascript_include_tag
,它通常放在您的application.html.erb
文件中。 If you have other files js files that are separately bundled, don't forget to add them to application.html.erb
.如果你有其他单独捆绑的文件 js 文件,不要忘记将它们添加到application.html.erb
。
If you have a precompile array in your app/config/environments/production.rb
folder (see below for an example) then perhaps you should move them over to your manifest.js
if they are not already accessed above.如果您的app/config/environments/production.rb
文件夹中有一个预编译数组(请参见下面的示例),那么如果上面尚未访问它们,那么也许您应该将它们移到您的manifest.js
中。
config.assets.precompile = ["admin.js", "admin.css"] config.assets.precompile = ["admin.js", "admin.css"]
Presumably you will want your admin.js
javascript file separate from your application.js
file.大概你会希望你的admin.js
javascript 文件与你的application.js
文件分开。 No problem, just tell sprockets to keep them separate:没问题,只需告诉 sprocket 将它们分开即可:
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link "admin.js"
Reference: read here for further details re: manifest.js. 参考:阅读此处了解更多详细信息:manifest.js。 file 文件
Source: Thanks to Richard Schneeman's blog - see here for more information.. 资料来源:感谢 Richard Schneeman 的博客 - 请参阅此处了解更多信息。
EDIT: if things are confusing / not clear: complain loudly!编辑:如果事情令人困惑/不清楚:大声抱怨! How can I fix if you keep mum?如果你保持沉默,我该如何解决? everyone benefits by these improvements.每个人都受益于这些改进。
A new major version of sprockets was recently released which is not compatible with the previous version.最近发布了一个新的 sprockets 主要版本,它与以前的版本不兼容。
Either perform the steps needed to upgrade or pin to version 3.x in Gemfile在 Gemfile 中执行升级或固定到版本 3.x 所需的步骤
gem 'sprockets', '~>3.0'
Based on the answer here you may be able to solve this with:根据此处的答案,您可以通过以下方式解决此问题:
mkdir -p app/assets/config && echo '{}' > app/assets/config/manifest.js
And if you need more details, the answer in this thread helpfully points to the Guide to upgrading from Sprockets 3.x to 4.x如果您需要更多详细信息,此线程中的答案有助于指向从 Sprockets 3.x 升级到 4.x 的指南
As suggested by link http://www.redmine.org/boards/2/topics/58169 , it is a known issue.正如链接http://www.redmine.org/boards/2/topics/58169所建议的,这是一个已知问题。 See #32223 and sprockets 4.0.0 breaks Redmine 3.4.11 with Ruby <2.5.0.请参阅#32223 和 sprockets 4.0.0 破坏 Redmine 3.4.11,Ruby <2.5.0。
I just reproduced this issue with redmine 3.4.4, but found everything is ok with Redmine 3.4.12.我刚刚用 redmine 3.4.4 重现了这个问题,但发现 Redmine 3.4.12 一切正常。
wget http://www.redmine.org/releases/redmine-3.4.12.tar.gz wget http://www.redmine.org/releases/redmine-3.4.12.tar.gz
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.