ruby - Gemfile `Bundler cannot continue` 意外 ':' 错误 [Ruby]

标签 ruby jekyll bundler

我是 Ruby 新手。运行命令bundle update 时出现错误。这就是我的 Gemfile 的样子:

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "jekyll", "~> 3.8"

gem "github-pages", group: :jekyll_plugins

plugins:
  - jekyll-sitemap
  - jekyll-paginate
  - jekyll-redirect-from
  - github-pages

这是我运行bundle update时遇到的错误:


[!] There was an error parsing `Gemfile`: syntax error, unexpected ':', expecting end-of-input - plugins:
       ^
. Bundler cannot continue.

 #  from /home/<user>/Documents/projects/<user>.github.io/Gemfile:10
 #  -------------------------------------------
 #  
 >  plugins:
 #    - jekyll-sitemap

期待有关如何解决此问题的任何指示。谢谢!

最佳答案

您的 Gemfile 是 Bundler 的 Ruby 文件,它指定您的项目需要的 gem。您在 Gemfile 中编写的 plugins: 部分是 YAML,旨在进入 _config.yml,而不是 Ruby,因此出现语法错误。

您需要将 Gemfile 的这一部分重写为 Ruby,位于 gem 组 jekyll_plugins 中,以便 Jekyll 知道使用这些 gem 作为插件:

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "jekyll", "~> 3.8"

group :jekyll_plugins do
  gem "jekyll-sitemap"
  gem "jekyll-paginate"
  gem "jekyll-redirect-from"
  gem "github-pages"
end

还有其他方法可以做到这一点,listed on the Jekyll documentation ,但我推荐这个。

关于ruby - Gemfile `Bundler cannot continue` 意外 ':' 错误 [Ruby],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59919634/

相关文章:

ruby-on-rails - 如何在 Ruby 中使用 RbVmomi 调整 VM 磁盘大小

ruby - `%i` 符号的起源是什么?

ruby-on-rails - 设置属性问题

ruby - 'array.each do |block|'在生成的 Haml HTML 中包含语句的结果

jekyll - Github Pages 以与以前不同的方式生成我的网站

jekyll - 如何使用 Liquid 对 Jekyll 的数据项进行分页

jekyll - 如何删除 Jekyll 中的空白?

ruby - 使用 RVM 本地 gemset 和使用 Bundle exec 之间有区别吗?

ruby-on-rails - 部署到heroku时清理 bundle 程序缓存

ruby-on-rails - rake : List/Remove custom rake task in specific environment (development/production )