简体   繁体   English

为什么 Rails 无法启动并显示“预期在 `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError) 中找到清单文件”?

[英]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)

What's happening?发生了什么?

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".您需要创建一个,并添加一些“指令”。

Why do I need to do this?为什么我需要这样做?

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" “链轮,请”

  • bundle everything in folder abc together将文件夹abc中的所有内容捆绑在一起
  • bundle AND concatenate everything in folder xyz捆绑并连接文件夹xyz中的所有内容
  • keep admin.js separate.保持admin.js分开。

Easy Steps To Solve the Problem:解决问题的简单步骤:

  1. Create the manifest.js file创建 manifest.js文件

    $ mkdir -p app/assets/config $ touch app/assets/config/manifest.js (not the root rails directory)
  2. 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

  1. 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"
  1. Lastly, if you are using webpacker, you might want to decide what you want handled by the asset pipeline and what you want handled by webpacker.最后,如果您使用的是 webpacker,您可能需要决定资产管道处理的内容以及 webpacker 处理的内容。 ie remove the link_directory to the javascripts file according to your own particular use cases.即根据您自己的特定用例将link_directory 删除到javascripts 文件。

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.

相关问题 Rails 6 如何链接 assets/config/manifest.js 中的子文件夹 - Rails 6 how to link subfolders in assets/config/manifest.js 链轮清单文件-Dual Rails 3 / Rails 4 - Sprockets manifest file - dual Rails 3 / Rails 4 找不到Rails资产清单文件 - Rails assets manifest file not found Rails 动态资产超时错误:::Sprockets::Railtie.build_environment(Rails.application).find_asset(&quot;#{params[:controller]}.css&quot;) - Rails dynamic assets Timeout error: ::Sprockets::Railtie.build_environment(Rails.application).find_asset("#{params[:controller]}.css") Rails资产管道使用配置文件和清单文件之间的区别 - Rails assets pipeline difference between using config file and using manifest file rails生成rspec:install - 没有这样的文件加载--sprockets / railtie(LoadError) - rails generate rspec:install - no such file to load --sprockets/railtie (LoadError) 使用资产管道的清单文件中的Sprockets :: CircularDependencyError - Sprockets::CircularDependencyError in manifest file using asset pipeline Rails.application.assets_manifest.find_sources(“#{params [:controller]}。js”)。是吗? 在Heroku上崩溃 - Rails.application.assets_manifest.find_sources(“#{params[:controller]}.js”).any? crashes on Heroku 提供了“applications.js”清单中未提及的 Rails 5 资产? - Rails 5 assets not mentioned on the `applications.js` manifest are served? Capistrano由于资产而部署缓慢-.sprockets-manifest * - Capistrano deploy slow due to assets - .sprockets-manifest*
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM