【问题标题】:jekyll 4.0.0 | Error: uninitialized constant TZInfo::Timezone杰基尔 4.0.0 |错误:未初始化常量 TZInfo::Timezone
【发布时间】:2022-12-25 17:23:21
【问题描述】:

我想在实时服务器上查看网站..但我还不熟悉 jekyll

首先我尝试了bundle exec jekyll serve,这是原子终端的输出:

    PS C:\Users\user\Documents\GitHub\bioscreator-lp> bundle exec jekyll serve
    Configuration file: C:/Users/user/Documents/GitHub/bioscreator-lp/_config.yml
    Dependency Error: Yikes! It looks like you don't have tzinfo or one of its dependencies 
    installed. In order to use Jekyll as currently configured, you'll need to ins
    tall this gem. If you've run Jekyll with `bundle exec`, ensure that you have included the 
    tzinfo gem in your Gemfile as well. The full error message from Ruby is: 'can
    not load such file -- tzinfo' If you run into trouble, you can find helpful resources at 
    https://jekyllrb.com/help/!
    jekyll 4.0.0 | Error:  tzinfo
    C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/jekyll-4.0.0/lib/jekyll/external.rb:73:in `rescue 
    in block in require_with_graceful_fail': tzinfo (Jekyll::Errors::MissingDepend
    encyException)

经过一些研究后,我尝试将 gem 'tzinfo-data' 放入 gemfile 并运行 bundle install 运行bundle exec jekyll serve

还有另一个错误:

     PS C:\Users\user\Documents\GitHub\bioscreator-lp> bundle exec jekyll serve
     Configuration file: C:/Users/user/Documents/GitHub/bioscreator-lp/_config.yml
     jekyll 4.0.0 | Error:  uninitialized constant TZInfo::Timezone

    tz = TZInfo::Timezone.get(timezone)
               ^^^^^^^^^^
     C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/jekyll-4.0.0/lib/jekyll/utils/win_tz.rb:16:in 
    `calculate': uninitialized constant TZInfo::Timezone (NameError)

    tz = TZInfo::Timezone.get

我在 stackoverflow 中找到了另一个解决方案,但看起来它只适用于旧版本的 jekyll ..我的版本是 4.0.0

【问题讨论】:

  • 你能解决吗?如果是这样,我对你是如何做到的很感兴趣。

标签: ruby jekyll tzinfo


【解决方案1】:

奇怪的错误。我知道我过去也遇到过类似的问题。 Jekyll 4.2.2 正在为我工​​作。我在 Windows 上,这就是我使用 WSL 设置 Jekyll 的方式。

配置

我的宝石文件(安装后包括两个不同的 tz gem)

安装还添加了具有固定最大版本的 tzinfo gem。

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
platforms :mingw, :x64_mingw, :mswin, :jruby do
  gem "tzinfo", "~> 1.2"
  gem "tzinfo-data"
end

我读到了一些关于 bundler gem 中的错误,可以通过删除平台来解决,但也许这已经解决了。这些平台根本不应该发挥作用,如果您不在 Windows 上,则可以将其省略。

红宝石版本

ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]

安装

安装 Jekyll gem

user@DESKTOP:/mnt/c/Users/User$ gem install jekyll
...
Fetching jekyll-4.2.2.gem
...
6 gems installed

创建 Jekyll 页面

user@DESKTOP:/mnt/c/Users/User$ jekyll new testpage
Running bundle install in /mnt/c/Users/User/testpage...
  Bundler: Fetching gem metadata from https://rubygems.org/............
  Bundler: Resolving dependencies...
  ...
  Bundler: Bundle complete! 7 Gemfile dependencies, 31 gems now installed.
  Bundler: Use `bundle info [gemname]` to see where a bundled gem is installed.
New jekyll site installed in /mnt/c/Users/User/testpage.

将 webrick 添加到 Gemfile(也许你不需要)

user@DESKTOP:/mnt/c/Users/User$ cd testpage/
user@DESKTOP:/mnt/c/Users/User/testpage$ bundle add webrick

启动 Jekyll 服务器

user@DESKTOP:/mnt/c/Users/User/testpage$ jekyll s
Configuration file: /mnt/c/Users/User/testpage/_config.yml
            Source: /mnt/c/Users/User/testpage
       Destination: /mnt/c/Users/User/testpage/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 0.41 seconds.
                    Auto-regeneration may not work on some Windows versions.
                    Please see: https://github.com/Microsoft/BashOnWindows/issues/216
                    If it does not work, please upgrade Bash on Windows or run Jekyll with --no-watch.
 Auto-regeneration: enabled for '/mnt/c/Users/User/testpage'
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

【讨论】:

    猜你喜欢
    • 2012-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 2011-02-25
    相关资源
    最近更新 更多