【问题标题】:Can't execute bundle exec rake db:migrate due to tzinfo error由于 tzinfo 错误,无法执行 bundle exec rake db:migrate
【发布时间】:2016-04-10 20:20:58
【问题描述】:

如标题所述。我得到了

C:\...>bundle exec rake db:migrate
rake aborted!
LoadError: cannot load such file -- tzinfo
C:/.../config/application.rb:3:in `require'
C:/.../config/application.rb:3:in `<top (required
)>'
C:/.../Rakefile:4:in `require'
C:/.../Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

我的 rails 是 v4.2.2,而我的 ruby​​ 在 Windows 8(64 位)上是 v2.2。根据我经历的各种 SO 问题,由于特定宝石之间的一些不兼容,我可能会收到此错误。因此,这是我的 gemfile,其中一些选项已经尝试过。

source 'https://rubygems.org'

gem 'rails',        '4.2.2'
gem 'sass-rails',   '5.0.2'
gem 'uglifier',     '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks',   '2.3.0'
gem 'jbuilder',     '2.2.3'
gem 'sdoc',         '0.4.0', group: :doc
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
#gem 'tzinfo',       '1.2.2'

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  #gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
end

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

有什么线索吗?

更新

我的 gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.2.2)
      actionpack (= 4.2.2)
      actionview (= 4.2.2)
      activejob (= 4.2.2)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.2)
      actionview (= 4.2.2)
      activesupport (= 4.2.2)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.1)
    actionview (4.2.2)
      activesupport (= 4.2.2)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.1)
    activejob (4.2.2)
      activesupport (= 4.2.2)
      globalid (>= 0.3.0)
    activemodel (4.2.2)
      activesupport (= 4.2.2)
      builder (~> 3.1)
    activerecord (4.2.2)
      activemodel (= 4.2.2)
      activesupport (= 4.2.2)
      arel (~> 6.0)
    activesupport (4.2.2)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    arel (6.0.3)
    builder (3.2.2)
    byebug (3.4.0)
      columnize (~> 0.8)
      debugger-linecache (~> 1.2)
      slop (~> 3.6)
    coffee-rails (4.1.0)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.10.0)
    columnize (0.9.0)
    concurrent-ruby (1.0.1)
    debugger-linecache (1.2.0)
    erubis (2.7.0)
    execjs (2.6.0)
    globalid (0.3.6)
      activesupport (>= 4.1.0)
    i18n (0.7.0)
    jbuilder (2.2.3)
      activesupport (>= 3.0.0, < 5)
      multi_json (~> 1.2)
    jquery-rails (4.0.3)
      rails-dom-testing (~> 1.0)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    json (1.8.3)
    loofah (2.0.3)
      nokogiri (>= 1.5.9)
    mail (2.6.4)
      mime-types (>= 1.16, < 4)
    mime-types (3.0)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0221)
    mini_portile2 (2.0.0)
    minitest (5.8.4)
    multi_json (1.11.2)
    nokogiri (1.6.7.2-x86-mingw32)
      mini_portile2 (~> 2.0.0.rc2)
    pg (0.17.1-x86-mingw32)
    rack (1.6.4)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.2.2)
      actionmailer (= 4.2.2)
      actionpack (= 4.2.2)
      actionview (= 4.2.2)
      activejob (= 4.2.2)
      activemodel (= 4.2.2)
      activerecord (= 4.2.2)
      activesupport (= 4.2.2)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.2)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.7)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6.0)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.3)
      loofah (~> 2.0)
    rails_12factor (0.0.2)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.5)
    rails_stdout_logging (0.0.5)
    railties (4.2.2)
      actionpack (= 4.2.2)
      activesupport (= 4.2.2)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (11.1.2)
    rdoc (4.2.2)
      json (~> 1.4)
    sass (3.4.22)
    sass-rails (5.0.2)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (~> 1.1)
    sdoc (0.4.0)
      json (~> 1.8)
      rdoc (~> 4.0, < 5.0)
    slop (3.6.0)
    spring (1.1.3)
    sprockets (3.6.0)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.0.4)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    sqlite3 (1.3.9-x86-mingw32)
    thor (0.19.1)
    thread_safe (0.3.5)
    tilt (1.4.1)
    turbolinks (2.3.0)
      coffee-rails
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    tzinfo-data (1.2016.3)
      tzinfo (>= 1.0.0)
    uglifier (2.5.3)
      execjs (>= 0.3.0)
      json (>= 1.8.0)

PLATFORMS
  x86-mingw32

DEPENDENCIES
  byebug (= 3.4.0)
  coffee-rails (= 4.1.0)
  jbuilder (= 2.2.3)
  jquery-rails (= 4.0.3)
  pg (= 0.17.1)
  rails (= 4.2.2)
  rails_12factor (= 0.0.2)
  sass-rails (= 5.0.2)
  sdoc (= 0.4.0)
  spring (= 1.1.3)
  sqlite3 (= 1.3.9)
  turbolinks (= 2.3.0)
  tzinfo-data
  uglifier (= 2.5.3)

【问题讨论】:

  • 您在删除tzinfo 后是否bundle install
  • 是的,我在每次更改后都这样做了。事实上,原始 gemfile(我正在阅读教程)不包含 tzinfo 和 tzinfodata。

标签: ruby-on-rails ruby ruby-on-rails-4 tzinfo


【解决方案1】:

gem 'tzinfo-data' 在 Windows 上开发时是必需的(通常在 Windows 机器上创建 Rails 应用程序时,Gemfile 会自动包含它)。

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] 添加到Gemfile,将tzinfo 注释掉并运行bundle update

【讨论】:

  • 不起作用。没有什么变化。我更新了我的原始问题以提供更多详细信息。
【解决方案2】:

感谢大家的建议,对我帮助很大。解决我的问题的正确方法是:

  • 删除 gemfile.lock
  • 将 tzinfo 版本降低到 1.2.1,并保持 tzinfo-data 不变 由用户 3097405 提供。
  • 然后出现另一个错误,所以我不得不将 sqlite3 版本增加到 1.3.11。事实证明我可以取消 webconsle。

所以,最终 Gemfile 看起来像这样

source 'https://rubygems.org'

gem 'rails',        '4.2.2'
gem 'sass-rails',   '5.0.2'
gem 'uglifier',     '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks',   '2.3.0'
gem 'jbuilder',     '2.2.3'
gem 'sdoc',         '0.4.0', group: :doc
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
gem 'tzinfo',       '1.2.1'

group :development, :test do
  gem 'sqlite3',     '1.3.11'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
end

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

再一次bundle install rake 命令正确执行。

【讨论】:

    【解决方案3】:

    您可能在requireing tzinfo 有一个杂散的参考。文本搜索是否在您的代码中找到对它的任何引用?

    还要确保tzinfo 不在您的Gemfile.lock 中。如果是,请删除 Gemfile.lock 并重新运行捆绑程序。

    【讨论】:

    • 不起作用。没有什么变化。我已更新我的原始问题以提供更多详细信息。
    【解决方案4】:
    gem install tzinfo-data
    

    然后将其添加到站点根目录中的 Gemfile 中:

    gem 'tzinfo-data'
    

    【讨论】:

      猜你喜欢
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      • 2012-04-08
      • 2016-07-06
      • 1970-01-01
      相关资源
      最近更新 更多