启动新的 Rails 项目时出现 tzinfo-data 问题

Don*_*ald 2 ruby-on-rails

启动新的 Rails 项目时遇到 TZInfo::DataSourceNotFound 问题,即使在 Gemfile 中输入

当我启动一个新的 Rails 项目时,遇到以下错误:
C:>rails new demo2 create
create README.md
create Rakefile
create .ruby-version
create config.ru
create .gitignore
create Gemfile
run git init from "."
创建 package.json
创建应用程序
创建 app/assets/config/manifest.js
创建 app/assets/javascripts/application.js
创建 app/assets/javascripts/cable.js
创建 app/assets/stylesheets/application.css
创建 app/channels /application_cable/channel.rb
创建app/channels/application_cable/connection.rb
创建app/controllers/application_controller.rb
创建app/helpers/application_helper.rb
创建app/jobs/application_job.rb
创建app/mailers/application_mailer.rb
创建应用程序/models/application_record.rb
创建app/views/layouts/application.html.erb
创建app/views/layouts/mailer.html.erb
创建app/views/layouts/mailer.text.erb
创建app/assets/images/。继续
创建应用程序/资产/javascripts/channels
创建应用程序/资产/javascripts/channels/.keep
创建应用程序/控制器/关注点/.keep
创建应用程序/模型/关注点/.keep
创建 bin
创建 bin/bundle
创建 bin/rails
创建 bin /rake
创建 bin/setup
创建 bin/update
创建 bin/yarn
创建配置
创建 config/routes.rb
创建 config/application.rb
创建 config/environment.rb
创建 config/cable.yml
创建 config/puma.rb
创建 config/storage .yml
创建配置/环境
创建配置/环境/开发.rb
创建配置/环境/生产
.rb 创建配置/环境/测试.rb
创建配置/初始化器
创建配置/初始化器/application_controller_renderer.rb
创建配置/初始化器/assets.rb
创建config/initializers/backtrace_silencers.rb
创建config/initializers/content_security_policy.rb
创建config/initializers/cookies_serializer.rb
创建config/initializers/cors.rb
创建config/initializers/filter_parameter_logging.rb
创建config/initializers/inflections.rb
创建配置/initializers/mime_types.rb
创建 config/initializers/new_framework_defaults_5_2.rb
创建 config/initializers/wrap_parameters.rb
创建 config/locales
创建 config/locales/en.yml
创建 config/master.key
追加 .gitignore
创建 config/boot.rb
创建 config/database.yml
创建 db
创建 db/seeds.rb
创建lib
创建 lib/tasks
创建 lib/tasks/.keep
创建 lib/assets
创建 lib/assets/.keep
创建日志
创建 log/.keep
创建公共
创建公共/404.html
创建公共/422.html
创建公共/500.html
创建 public/apple-touch-icon-precomposed.png
创建 public/apple-touch-icon.png
创建 public/favicon.ico
创建 public/robots.txt
创建 tmp
创建 tmp/.keep
创建 tmp/cache
创建 tmp/cache/资产
创建供应商
创建供应商/.keep
创建测试/
夹具 创建测试/夹具/.keep
创建测试/夹具/文件
创建测试/夹具/文件/.keep
创建测试/控制器
创建测试/控制器/.keep
创建测试/邮件
创建测试/mailers/.keep
创建测试/模型创建 测试/
模型/.keep 创建测试/帮助程序 创建测试/helpers/.keep 创建测试/集成 创建测试/集成/.keep 创建测试/test_helper.rb 创建测试/系统 创建test/system/.keep 创建 test/application_system_test_case.rb 创建存储 创建 storage/.keep 创建 tmp/storage 创建 tmp/storage/.keep 删除 config/initializers/cors.rb 删除 config/initializers/new_framework_defaults_5_2.rb 运行捆绑 安装Bundler 正在安装的任何平台都不会使用依赖项 tzinfo-data (>= 0)。Bundler 正在为 ruby​​ 安装,但依赖项仅适用于 x86-mingw32、x86-mswin32、x64-mingw32、java。要将这些平台添加到捆绑包中,请运行bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java。从https://rubygems.org/ 获取 gem 元数据............ 从https://rubygems.org/获取 gem 元数据。 正在解决依赖关系... 无法在集合中找到满足 tzinfo-data (>= 0) 的规范。也许锁定文件已损坏?



















我按照上面的建议操作:
bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java

然后:
捆绑安装

一切看起来都很好。

当我尝试启动 Rails 服务器时,遇到以下错误:
C:\demo2>rails server
=> Booting Puma
=> Rails 5.2.2 application starting in development
=> Run rails server -h for more startup options
Exiting
Traceback (most 最近一次调用最后):
57: from bin/rails:4:in ' 56: from C:/Ruby25-x64/ lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependency.rb:291:in require'
55: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0 /gems/activesupport-5.2.2/lib/active_support/dependency.rb:257:in load_dependency' 54: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/ lib/active_support/dependency.rb:291:in block in require'
53: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext /kernel_require.rb:29:in require' 52: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb: 20:在require_with_bootsnap_lfi'51
:来自C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:在寄存器
'50:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in block in require_with_bootsnap_lfi'
49: 来自 C: /Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in require' 48: 来自 C:/Ruby25-x64/ lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands.rb:18:in '
47: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/ gems/railties-5.2.2/lib/rails/command.rb:46:in调用46:来自C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/ Rails/command/base.rb:65:in 执行'45
:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in分派 44:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocable.rb:126:in invoke_command'
43:来自 C:/Ruby25- x64/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:运行42:来自C:/Ruby25-x64/lib/ruby/gems/2.5。 0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:142:执行'41
:来自C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties -5.2.2/lib/rails/commands/server/server_command.rb:142:in tap' 40: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.2/ lib/rails/commands/server/server_command.rb:147:in 执行块中'39
:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails /commands/server/server_command.rb:51:in start' 38: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/ server_command.rb:89:in log_to_stdout'
37: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/server.rb:354:inwrapped_app' 36:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:27:在应用程序中'
35:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/server.rb:219:in app' 34:来自 C:/Ruby25-x64 /lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/server.rb:319:in build_app_and_options_from_config'
33:来自 C:/Ruby25-x64/lib/ruby/gems/2.5。 0/gems/rack-2.0.6/lib/rack/builder.rb:40:in parse_file'
32: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rack-2.0.6 /lib/rack/builder.rb:49:in new_from_string'
31:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb: 49:在 eval 中 30:来自 config.ru:在 29:来自 config.ru:在 new 中 28:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rack-2.0。 6/lib/rack/builder.rb:55:在初始化'27
:来自C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb :55:在instance_eval'26:来自config.ru:3:在'25中的块
:来自C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap /load_path_cache/core_ext/kernel_require.rb:44:in require_relative' 24: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependency.rb: 291:在需要
'23:来自C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependency.rb:257:在load_dependency'22:来自C :/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependency.rb:291:在 require'
21 中的块:来自 C:/Ruby25-x64/lib /ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in require'
20: 来自 C:/Ruby25-x64/lib/ruby/gems/ 2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in require_with_bootsnap_lfi'19
:来自C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems /bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:在寄存器
'18:来自C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/ lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in block in require_with_bootsnap_lfi'
17: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap /load_path_cache/core_ext/kernel_require.rb:21:in require' 16:来自 C:/demo2/config/environment.rb:5:in '
15:来自 C:/Ruby25-x64/lib/ruby/gems/2.5。 0/gems/railties-5.2.2/lib/rails/application.rb:361:初始化!' 14:来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/initialized.rb:60:in run_initializers'
13:来自 C:/Ruby25-x64 /lib/ruby/2.5.0/tsort.rb:205:in tsort_each' 12: 来自 C:/Ruby25-x64/lib/ruby/2.5.0/tsort.rb:226:in tsort_each'
11: 来自 C: /Ruby25-x64/lib/ruby/2.5.0/tsort.rb:347:in every_strongly_connected_component' 10: 来自 C:/Ruby25-x64/lib/ruby/2.5.0/tsort.rb:347:in call'
9: 来自 C:/Ruby25-x64/lib/ruby/2.5.0/tsort.rb:347:in every' 8: 来自 C:/Ruby25-x64/lib/ruby/2.5.0/tsort.rb:349 :在each_strongly_connected_component'7中的块中
:来自C:/Ruby25-x64/lib/ruby/2.5.0/tsort.rb:431:在each_strongly_connected_component_from'6中:来自C:/Ruby25-x64/lib/ruby/2.5.0 /tsort.rb:350:in block (2 level) in every_strongly_connected_component'
5: 来自 C:/Ruby25-x64/lib/ruby/2.5.0/tsort.rb:228:in block in tsort_each' 4: 来自 C: /Ruby25-x64/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/initialized.rb:61:in block in run_initializers'
3: 来自 C:/Ruby25-x64/lib/ ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/initialized.rb:32:in run' 2: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems /railties-5.2.2/lib/rails/initialized.rb:32:in instance_exec'
1: 来自 C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/ active_support/railtie.rb:36:在 ' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/railtie.rb:39:in 救援中类中的块:Railtie':tzinfo-data 不存在。请将 gem 'tzinfo-data' 添加到您的 Gemfile 中并运行捆绑安装 (TZInfo::DataSourceNotFound)

已检查 Gemfile,条目是否有
gem 'tzinfo-data',平台:[:mingw, :mswin, :x64_mingw, :jruby]

环境:
Windows 10 64位
ruby 2.5.3p105(2018-10-18修订版65156)[x64-mingw32]
Rails 5.2.2

宝石文件:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'duktape'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
end

group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Don*_*ald 36

设法解决了这个问题。

步骤: 1. 在 Gemfile 中删除“gem 'tzinfo-data',platforms: [:mingw, :mswin, :x64_mingw, :jruby]”
2. 运行 gem uninstall tzinfo-data
3. 运行捆绑安装

重新安装回tzinfo-data后,rails服务器就可以启动了。

感谢您的建议和努力帮助我解决这个问题。